LONDON—Britain’s top court Wednesday upheld the right of a bakery to refuse a gay man’s order for a cake decorated with the message “Support Gay Marriage” on the grounds that forcing the bakers to make the cake would have impinged on their rights to free speech.

Following a yearslong legal case that cost over half a million dollars, Britain’s top court ruled the case wasn’t about discrimination but rather boiled down to a different issue—that people can refuse to promote messages they disagree with.

In...