The judges ruled that Germany had violated the rights to liberty and free assembly of the two activists, who were aged 22 at the time.
The two, identified as Sven Schwabe and M.G., were arrested in the northeastern city of Rostock on June 3, 2007, three days before the start of the summit of the world's most industrialized nations, and held until the day after the meeting closed.
They were among tens of thousands who had travelled to the region to demonstrate against the summit in the nearby Baltic Sea resort of Heiligendamm, where world leaders met behind a tight security cordon.
The two claimants were detained during a police identity check in a parking lot outside a prison, next to a van in which officers found banners, one of them proclaiming "Freedom for all prisoners".
The applicants have argued the slogan called on police to end the arrests of demonstrators, but a local court ordered their continued detention until June 9, suspecting they wanted to incite others to free the prisoners by force.
The protesters challenged the decision twice, to no avail.
The Strasbourg court found that the period of their detention – five and a half days – was "a considerable time" and said it was "not convinced" that their continuing detention could have reasonably been seen as necessary.
It also said that, if police had wanted to prevent them from inciting others to free the prisoners, it would have been sufficient to seize the banners.
The court found that the applicants, by planning to take part in the anti-G8 demonstrations, "had intended to participate in a debate on matters of public interest, namely the effects of globalisation on peoples lives."
"By displaying the slogans on their banners, they had aimed to criticize the security measures taken by the police, in particular the high number of detentions," the court said.
"Depriving them of their liberty for several days for trying to display the impugned banners had had a chilling effect on the expression of such an opinion and restricted public debate on that issue," the judges found.
The court ruled that Germany had violated their rights to liberty and freedom of association and awarded each applicant €3,000 in damages plus costs and expenses.