Legal aid attorneys and immigrant rights organizations had called for an end to the practice in recent years.
The immigration raids jeopardized public safety and discouraged victims and witnesses from reporting crimes and participating in the legal process, according to Brooklyn District Attorney Eric Gonzalez. He and New York Attorney General Letitia James filed the lawsuit against ICE and the U.S. Department of Homeland Security to end the practice.
"Allowing every resident equal access to our justice system is crucially important and necessary for maintaining fairness and public safety," Gonzalez said in a statement on the ruling.
James and Gonzalez filed their lawsuit in September. The Trump administration filed a motion to dismiss it, but Judge Jed Rakoff of the U.S. District Court for the Southern District of New York denied the motion in December.
In his ruling on Wednesday, Rakoff wrote, "It is one thing for the state courts to try to deal with the impediments brought on by a pandemic, and quite another for them to have to grapple with disruptions and intimidations artificially imposed by an agency of the federal government in violation of long-standing privileges and fundamental principles of federalism and of separation of powers."
According to a 2018 ACLU report, ICE agents have "dramatically expanded" their presence at courthouses under the Trump administration, with fear of deportation deterring some immigrants from reporting crimes.
A 2019 study by the Immigrant Defense Project found that ICE arrests and sightings in and around New York state courts increased by 1,700% in 2018 compared to 2016.
"Our victory over the Trump administration's over-policing policies ensures the important work happening in local courts will continue undeterred without the targeting of immigrants seeking access to our courts," James said in a statement.
ABC News' Aaron Katersky contributed to this report.