WASHINGTON — Overly broad state laws that ban wearing political messages inside polling places are unconstitutional, the Supreme Court ruled Thursday.

The 7-2 decision struck down a century-old Minnesota law that was challenged by a voter temporarily turned away for wearing a Tea Party shirt and a "Please I.D. Me" button. During oral argument in February, state officials said the law had not been challenged until now.

Chief Justice John Roberts issued the court's opinion, calling the state's effort to make polling places less clamorous admirable. But unlike some other states, including California and Texas, he said, "Minnesota has not supported its good intentions with a law capable of reasoned application."

Justices Sonia Sotomayor and Stephen Breyer dissented, saying Minnesota's highest court should have an opportunity to weigh in first. Sotomayor had expressed support for the state law during oral argument in February, noting some people viewed "Please I.D. Me" as a "highly charged political message ... intended to intimidate people to leave the polling booth."

More: Divided over partisan election maps, Supreme Court could learn a lesson from divided college campus

More: Supreme Court says states can remove voters who skip elections, ignore warnings

All 50 states regulate campaign advocacy in and around polling places for reasons most of the justices readily defended during oral argument. But only 10 states extend the prohibition to virtually anything deemed political.

Federal district and appeals courts dismissed the complaints from Andrew Cilek and the Minnesota Voters Alliance, but the Supreme Court has been protective of free speech rights even when it disagrees with the message.

Several justices had expressed concern about how to draw a line between banned and acceptable messages. A majority agreed that the right to vote deserves a little peace and quiet; the issue was, how much?

"We see no basis for rejecting Minnesota’s determination that some forms of advocacy should be excluded from the polling place," Roberts said. "In light of the special purpose of the polling place itself, Minnesota may choose to prohibit certain apparel there because of the message it conveys, so that voters may focus on the important decisions immediately at hand."

The problem, Roberts said, is that Minnesota's prohibition doesn't specify what's allowed and what isn't, leaving too much up to the whim of temporary polling place officials. The state bans "issue-oriented material" as well as "material promoting a group with recognizable political views."

"The American Civil Liberties Union, the AARP, the World Wildlife Fund, and Ben & Jerry’s all have stated positions on matters of public concern," Roberts said. "If the views of those groups align or conflict with the position of a candidate or party on the ballot, does that mean that their insignia are banned?"

The case was one of several before the court this term that affect voting, which the justices have quarreled over for years following their landmark 5-4 decision in 2013 striking down a key section of the Voting Rights Act. 

The justices also heard disputes over partisan gerrymandering in Wisconsin and Maryland, racial redistricting in Texas and Ohio's method of purging voters from registration rolls, which they upheld in a 5-4 decision Monday.

The Supreme Court in 1992 upheld a state law establishing 100-foot, campaign-free buffer zones around polling places. That law and others generally apply to active electioneering, not passive wardrobes.

The Minnesota case raised troubling new questions. Can a state prohibit voters from wearing a "Make America Great Again" or "#MeToo" T-shirt? How about displaying the gay rights movement's rainbow flag, or "Parkland Strong" to support the Florida community shaken by February's school shooting?

And why would it be OK to herald First Amendment freedom of speech rights across one's chest, but not Second Amendment rights affecting firearms -- a differentiation Minnesota allowed? 

"The problem is that so many things have political connotations," Justice Samuel Alito said in February. "There are always going to be hard calls."

Justice Anthony Kennedy, on the other hand, wondered if the polling place should be a politics-free zone.

"Why should there be any speech there at all?" he said. "You're there to vote."

More: Immigration, gay rights, politics, abortion, taxes, technology: Crunch time at the Supreme Court

More: Supreme Court takes on Democrats and Republicans over one-sided maps

More: Political maps under fire as Supreme Court case on tailor-made districts looms