A federal judge in Washington, D.C., on Wednesday ruled against the Administrative Office of the U.S. Courts' code banning staff from participating in political speech, finding the office went too far in implementing the prohibitions.

The AO adopted the restrictions in 2018, which included bans on staff donating to candidates and belonging to political parties. Director James Duff argued they were necessary in part to maintain the independence of the judiciary, but two staffers alleged it violated their First Amendment rights in a lawsuit brought forward by the American Civil Liberties Union.

U.S. District Judge Christopher "Casey" Cooper issued a preliminary injunction in 2019, temporarily halting all but two of the restrictions from going into effect. On Wednesday, he made that injunction permanent and ruled the code only applied to top AO officials, including Duff.

In a 46-page opinion, Cooper said the country's political discourse is "fractious and hyper-partisan" and some might "seek to exploit those divisions—through social media or other means—to advance their position on a policy issue or legislative proposal affecting the judicial branch." He applauded the AO's efforts to "counter these potential effects."

"But allowing the challenged restrictions to stand because someone might twist routine civic expression to their political advantage strikes the court as akin to endorsing the proverbial heckler's veto: muffling the speaker in anticipation of a hostile overreaction by the listener," Cooper wrote.

Referencing declarations submitted by government officials about how members of Congress and their staff might take issue with the AO because of a staffer's political activity, Cooper said "the problem would lie with Congress (and indeed the country), not the AO."

"In this court's view at least, the First Amendment freedoms of fair and dedicated professionals should not be sacrificed at the altar of partisan myopia," the judge wrote.

However, Cooper did allow two of the AO's restrictions to remain in place: Those blocking staff from organizing events for candidates and from driving voters to the polls on behalf of a party or candidate.

"Because they involve more committed and visible participation in elections and campaign management, a member of the public could more reasonably conclude that these two activities demonstrate a partisan tie so enduring that it could inspire an AO employee to inject partisan affiliations into her performance of day-to-day duties," Cooper wrote.

The ruling comes amid a debate on the politicization of the court system. President Donald Trump and others have attacked federal judges who have ruled against them, citing the political affiliations of the president who tapped them for the bench, as Trump has reshaped the federal judiciary with his own appointees.

Some, including Chief Justice John Roberts, have at times spoken out against those remarks, saying they undermine the integrity of the courts.