The U.S. Supreme Court ruled Monday in favor of a Colorado baker who objected to making a cake for a gay couple’s wedding due to his religious opposition to gay marriage.

The justices ruled 7-2 against the Colorado Civil Rights Commission, reversing a ruling from the Colorado Court of Appeals in one of the court’s most high-profile cases of the term. Justices Ruth Bader Ginsburg and Sonia Sotomayor dissented.

The court’s decision focused narrowly on the Colorado Civil Rights Commission’s actions toward baker Jack Phillips, saying the commission was hostile to his faith and failed to act neutrally toward his religion. Kennedy acknowledged the courts may rule differently in future cases that fall into the intersection of gay rights and religious freedom.

Writing for the majority, Kennedy argued the “commission’s treatment of Phillips’ case violated the state’s duty under the First Amendment not to base laws or regulations on hostility to a religion or religious viewpoint.

“[T]he record here demonstrates that the commission’s consideration of Phillips’ case was neither tolerant nor respectful of Phillips’ religious beliefs,” Kennedy wrote.

The 81-year-old justice also pointed to “official expressions of hostility to religion” made by members of the Colorado Civil Rights Commission, saying they were “inconsistent with what the Free Exercise Clause requires.”

“The commission’s hostility was inconsistent with the First Amendment’s guarantee that our laws be applied in a manner that is neutral toward religion,” Kennedy wrote. “Phillips was entitled to a neutral decisionmaker who would give full and fair consideration to his religious objection as he sought to assert it in all of the circumstances in which the case was presented, considered, and decided.”

Kennedy, though, left open the possibility that similar cases could end up before the courts.

“The outcome of cases like this in other circumstances must await further elaboration in the courts, all in the context of recognizing that these disputes must be resolved with tolerance, without undue burden disrespect to sincere religious beliefs, and without subjecting gay persons to indignities when they seek goods and services in an open market,” he wrote for the majority.

In her dissent, Ginsburg rejected the weight Kennedy gave to the comments from members of the Colorado Civil Rights Commission, writing that the remarks should not overshadow Phillips’ refusal to sell the couple the cake for their wedding.

“Whatever one may think of the statements in historical context, I see no reason why the comments of one or two commissioners should be taken to overcome Phillips’ refusal to sell a wedding cake to [Charlie] Craig and [Dave] Mullins,” she wrote. “The proceedings involved several layers of independent decisionmaking, of which the commission was but one.”

The case, Masterpiece Cake Shop Ltd v. Colorado Civil Rights Commission, was a dispute between Phillips, the baker, and Craig and Mullins, a gay couple who asked Phillips to bake a cake for their wedding reception.

Phillips told the couple he didn’t make cakes for same-sex weddings.

Craig and Mullins then filed a complaint with the Colorado Civil Rights Commission after learning the state’s public accommodations law barred discrimination on the basis of sexual orientation.

The commission ruled in favor of the gay couple, and a state appeals court agreed.

The justices were tasked with determining whether Colorado’s public accommodations law violated Phillips’ free speech rights, as the baker’s lawyers argued it forced Phillips to engage in speech that violated his religious beliefs.

In the wake of the Supreme Court’s landmark ruling legalizing gay marriage, florists, bakers, photographers and other business owners nationwide have been embroiled in legal challenges after turning down wedding services to same-sex couples due to their religious beliefs.

Courts often rule against the business owners, though, due to state laws that require businesses to serve customers regardless of sexual orientation.

Responding to the court’s ruling, the ACLU, which argued on behalf of Craig and Mullins, said the justices reaffirmed the principle that people cannot be discriminated against on the basis of their sexual orientation.

“The court reversed the Masterpiece Cakeshop decision based on concerns unique to the case but reaffirmed its longstanding rule that states can prevent the harms of discrimination in the marketplace, including against LGBT people,” Louise Melling, deputy legal director of the ACLU, said in a statement.

Craig and Mullins, meanwhile, vowed to continue fighting.

“We have always believed that in America, you should not be turned away from a business open to the public because of who you are,” they said in a statement. “We brought this case because no one should have to face the shame, embarrassment, and humiliation of being told ‘we don’t serve your kind here’ that we faced, and we will continue fighting until no one does.”

The Alliance Defending Freedom, which argued on behalf of Phillips, praised the Supreme Court for recognizing the Colorado Civil Rights Commission’s treatment of Phillip’s faith.

“Government hostility toward people of faith has no place in our society, yet the state of Colorado was openly antagonistic toward Jack’s religious beliefs about marriage. The court was right to condemn that,” Kristen Waggoner, senior counsel at the organization, said in a statement. “Tolerance and respect for good-faith differences of opinion are essential in a society like ours. This decision makes clear that the government must respect Jack’s beliefs about marriage.”

[Also read: The 6 blockbuster cases to watch as the Supreme Court term ends]