In the 2017 case, Matal v. Tam, the court ruled that an Asian-American dance-rock band called the Slants was entitled to federal trademark registration. (The decision also effectively allowed the Washington Redskins football team to register its trademarks.)

The justices seemed to find the provision at issue in Monday’s case more challenging. Mr. Stewart said the government would enforce the challenged provision narrowly in light of the 2017 decision, focusing on terms that are shocking or offensive based on the mode of their expression rather than on the ideas they convey.

Justice Elena Kagan responded that it would be strange for the court to interpret the law’s expansive language — barring “immoral” and “scandalous” terms — based on the government’s promise to enforce it sparingly. “These are very broad words,” she asked skeptically, “but we’re going to pretend that they say something much narrower than they do?”

Justice Stephen G. Breyer said the court should find a way to discourage a small subset of terms that he said have physiological effects on the human body. “It’s stored in a different place in the brain,” he said. “It leads to retention of the word.”

Justice Neil M. Gorsuch seemed sympathetic to that approach, though for a different reason. “There are certain words that are profane and that we, as a matter of civility in our culture, would like to see less of rather than more of,” he said.

Justice Ruth Bader Ginsburg, who is 86, said the young people who bought Mr. Brunetti’s wares may not be offended by the brand name. “A composite of, say, 20-year-olds,” she said, would not find the term particularly shocking.

“Suppose in the niche market that these goods are targeting, the name is mainstream,” she said. “These goods, as I understand it, are meant to attract a particular market, and if we concentrate on that market, from their perception, the word is mainstream.”