WASHINGTON — The Supreme Court ruled Thursday that unions must give nonmembers an immediate chance to object to unexpected fee increases or special assessments that all workers are required to pay in closed-shop situations.

The court ruled for Dianne Knox and other nonmembers of the Service Employees International Union’s Local 1000, who wanted to object and opt out of a $12 million special assessment the union required from its California public sector members for political campaigning. Knox and others said the union did not give them a legally required notice that the increase was coming.