Justice Ruth Bader Ginsburg reflected on the consequences of ruling against the union in the case before the court. “It drains it of resources that make it an equal partner” with the government in negotiations, she told William L. Messenger, a lawyer for Mark Janus, an Illinois child support specialist who objected to positions taken by his union in negotiations. “And then you’ll have a union with diminished resources, not able to investigate what it should demand at the bargaining table, not equal to the employer that it faces.”

Near the end of the argument, Justice Sonia Sotomayor said the case represented an existential threat to the labor movement. “You’re basically arguing, ‘Do away with unions,’ ” she told Mr. Messenger.

The case was a challenge to an Illinois law that requires government workers who choose not to join unions to “pay their proportionate share of the costs of the collective bargaining process, contract administration and pursuing matters affecting wages, hours and other conditions of employment.” More than 20 states have similar laws.

The Supreme Court ruled that such laws are constitutional in Abood v. Detroit Board of Education, a foundational 1977 decision that made a distinction between two kinds of compelled payments. Forcing nonmembers to pay for a union’s political activities violated the First Amendment, the court said. But it was constitutional, the court added, to require nonmembers to help pay for the union’s collective bargaining efforts to prevent freeloading and ensure “labor peace.”

Conservative groups have long urged the court to overrule the Abood decision, and they have repeatedly gotten close to their goal. In 2014, the court stopped just short of overruling the decision.

When the court revisited the issue in 2016, the Obama administration argued in favor of the unions. The Trump administration switched sides in the new case, prompting a comment from Justice Sotomayor to Solicitor General Noel J. Francisco.

“This is such a radical new position on your part,” she said.

Justice Kagan noted that the administration’s position could open the federal government to First Amendment challenges in various kinds of workplace disputes. “It strikes me as a very unusual position for the government to be taking,” Justice Kagan said, perhaps reflecting on her own experience in representing the government as solicitor general in the Obama administration.