WASHINGTON—The Trump administration told the Supreme Court Thursday that the First Amendment entitles a Colorado baker to turn away gay couples seeking wedding cakes, despite state law prohibiting discrimination based on sexual orientation.

While businesses that sell off-the-shelf goods may be bound by antidiscrimination laws, those that make custom products, like the Masterpiece Cakeshop in Lakewood, Colo., could be exempt if filling an order forces them to express views contrary to their own beliefs, the Justice Department said in a friend-of-the-court brief.