In the opinion issued by Justice Anthony Kennedy, the court disagreed with a Colorado court's previous ruling that the gay couple, Charlie Craig and Dave Mullins, had been discriminated against based on sexual orientation. The court ruled in favor of the appeal by the baker, Jack Phillips, 7-2, with only Justices Ruth Bader Ginsburg and Sonia Sotomayor dissenting.
The Supreme Court decision said the Colorado Civil Rights Commission was hostile to Phillips' first amendment rights and that his "religious objection was not considered with the neutrality that the Free Exercise Clause requires."
The court's ruling said that commissioners made statements that "showed elements of a clear and impermissible hostility" toward Phillips' sincere religious beliefs. It cited comments from one commissioner in the 2014 hearing that it was "despicable" to use religious rhetoric to justify discrimination.
Ginsburg said in her dissent that the ruling that the civil rights commission expressed bias was flawed because the statements of a few commissioners should not invalidate the entire case.
"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 Craig and Mullins," Ginsburg wrote.
But the Masterpiece Cakeshop case doesn't immediately set a precedent that future cases will rule in favor of businesses, according to ABC News' Supreme Court contributor and professor at Cardozo Law School Kate Shaw.
"Because of the way the Colorado state body considered this dispute, it used language in resolving the dispute that suggested real hostility to religion, and under these facts essentially the religious claim prevailed," she said. "So sometimes this balance gets struck in favor of religion and against the sort of rights against discrimination in the public sphere. But the court made very clear that all of these questions will be resolved on a case-by-case basis based on the facts of the case."
The Supreme Court's majority decision said that future cases must be weighed in the courts with respect to the rights of both individuals' religious rights and the rights of same-sex couples.
"In the context of recognizing that these disputes must be resolved with tolerance, without undue disrespect to sincere religious beliefs, and without subjecting gay persons to indignities when they seek goods and services in an open market," Kennedy wrote in the decision.
Justice Neil Gorsuch agreed with the opinion, writing that even though a wedding cake doesn't have words or symbols, it sends a message that celebrates a wedding and that the courts shouldn't force someone to convey that message if it is against their beliefs.
"At its most general level, the cake at issue in Mr. Phillips's case was just a mixture of flour and eggs; and its most specific level, it was a cake celebrating the same-sex wedding of Mr. Craig and Mr. Mullins," Gorsuch said.
Organizations supporting both sides in the case described it as a win in statements released after the decision on Monday.
The Alliance Defending Freedom, a nonprofit religious freedom organization that supported Phillips, said that the court was right to condemn punishment against creative professionals.
"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. 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,” Alliance Defending Freedom senior counsel Kristen Waggoner said in a statement.
The American Civil Liberties Union, which represented Mullins and Craig in the case, said the decision "reaffirmed the core principle" that businesses cannot discriminate against same-sex couples, even though this specific ruling was overturned.
"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," said Louise Melling, deputy legal director of the ACLU.
Craig and Mullins complained to the Colorado Civil Rights Commission after they sat down with Phillips, owner of Masterpiece Cakeshop, for a wedding cake design appointment and he told them that he did not design cakes for gay weddings.
He offered them baked goods, but said he would not bake them a custom cake, which he described as a form of artistic expression.
A Colorado court previously ruled that the baker violated the couple's civil rights under a state law that prohibits discrimination on the basis of sexual orientation. But Phillips appealed, argued that baking is a form of artistic expression and an important part of a wedding ceremony, and he could not participate in a wedding that violated his religious beliefs.
"I serve everybody, all the time," Phillips said on ABC’s "The View" last June. "But I don't make a cake for every event that's required of me."