A federal judge in California ruled Friday against the Trump administration’s plan to detain illegal immigrant families longer than 20 days, undercutting the president’s attempt to close the chief “loophole” that caused this year’s border surge.

Judge Dolly M. Gee, an Obama appointee, has long been a stumbling block for Homeland Security and its immigration plans, and the ruling was expected. The administration is likely to quickly appeal.

Homeland Security had asked Judge Gee to cancel the Flores agreement, a 1990s-era court settlement that sets out strict rules for how illegal immigrant children who arrive at the border without parents are treated. Judge Gee in 2015 expanded the agreement to children who arrive with parents.

Under her ruling, those migrants who came with children had to be released from custody in 20 days — even though it usually takes more than twice that time to complete a deportation case. Once released, the families disappeared into the shadows, and Judge Gee’s ruling became known as the “family loophole.”

The Trump administration had proposed a new deal that would roll the situation back to where it was in the Obama administration, where families could be detained, children and parents together, in dorm-like facilities until their cases are complete.

Judge Gee rejected that in a ruling Friday, according to advocates.

“I am pleased that our justice system has stopped the Trump Administration plans to indefinitely detain families in prison-like conditions,” said Rep. Joaquin Castro, chairman of the Congressional Hispanic Caucus. “This victory gives us hope and is a reminder to us all — elected officials, immigration lawyers, organizers, and advocates — to keep fighting.”

Security analysts say Judge Gee’s 2015 Flores update, which was upheld by the 9th U.S. Circuit Court of Appeals in 2016, has led to some children being abducted in Latin America, so adults can portray themselves as families at the border.

At its peak in May, the Border Patrol nabbed nearly 85,000 migrants that month who tried to sneak into the U.S. as families. That was more than 20 times higher than the number arrested in May 2015, before Judge Gee’s updated ruling took effect.

Immigrant-rights activists defend Flores, saying it ensures better treatment for families and children by getting them out of immigration custody quickly.

They argue the families should generally be considered refugees, not illegal immigrants.

Sign up for Daily Newsletters Manage Newsletters

Copyright © 2020 The Washington Times, LLC. Click here for reprint permission.