(CNN)State officials who argue ICE officers undermine the justice system when they make arrests at courthouses just won a significant victory.
US District Judge Jed S. Rakoff issued an order Wednesday blocking Immigration and Customs Enforcement from continuing the practice in New York state, calling the policy that led to an uptick in courthouse arrests there illegal.
For years, state and local officials have argued that when ICE officers intercept undocumented immigrants at courthouses -- where they are making appearances as defendants, witnesses or victims -- it endangers public safety by making it harder to prosecute crimes.
ICE has defended the arrests, saying apprehending people in controlled settings is safer than arresting them on the streets.
Rakoff's order blocks the agency from conducting any civil arrests on the premises of New York state courthouses "as well as such arrests of anyone required to travel to a New York State courthouse as a party or witness to a lawsuit."
ICE did not immediately respond to a request for comment.
In a statement, New York Attorney General Letitia James described the ruling as a "victory over the Trump Administration's over-policing policies."
The New York federal judge's order comes after the state and Brooklyn District Attorney Eric Gonzalez filed a lawsuit arguing that ICE's increasing arrests in and around courthouses were causing disruptions in the state's courts and the intimidation of parties and witnesses.
"For more than three years, I have been calling on ICE to stop its unconscionable practice of conducting immigration raids in and around our courthouses because they jeopardize public safety," Gonzalez said in a statement praising the judge's ruling.
"But the Trump Administration only escalated this unlawful and dangerous tactic, creating a chilling effect in immigrant communities, which discouraged victims and witnesses from reporting crimes and participating in the legal process."
Rakoff sided with the New York officials.
"Courthouse civil arrests are not lawful, because they contravene the common-law privilege ... that protects courts and litigants against these intimidating and disrupting intrusions," he said.
Last year, a federal judge in Massachusetts blocked ICE courthouse arrests there. An appeal in that case is pending.