WASHINGTON — The Supreme Court ruled on Monday that states must sometimes provide aid to religious groups even when their state constitutions call for a strict separation of church and state. The decision concerned a state program to make playgrounds safer that excluded those affiliated with churches, and it had implications for all kinds of government aid to religious institutions.

The vote was 7 to 2, though some of the justices in the majority differed about how broadly the court should have ruled.

Chief Justice John G. Roberts Jr., writing for the majority, said unjustified government discrimination against churches and other religious institutions is odious and unconstitutional. Officials in Missouri, Chief Justice Roberts wrote, were not entitled to reject a 2012 application from Trinity Lutheran Church, in Boone County, Mo., for a grant to use recycled tires to resurface a playground.

“The consequence is, in all likelihood, a few extra scraped knees,” Chief Justice Roberts wrote. “But the exclusion of Trinity Lutheran from a public benefit for which it is otherwise qualified, solely because it is a church, is odious to our Constitution all the same, and cannot stand.”