A judge in Los Angeles has blocked a Trump administration rule that sought to detain migrant families indefinitely, saying it was inconsistent with a 1997 court settlement that governs conditions for migrant children in US custody.

The 1997 settlement agreement, which originated in 1985 with a complaint brought on behalf of 15-year-old Salvadoran immigrant Jenny L Flores, set standards for humane treatment of children in detention and ordered their prompt release in most cases.

The Trump administration had hoped a new rule issued on 23 August would supersede that settlement.

“This regulation is inconsistent with one of the primary goals of the Flores agreement, which is to instate a general policy favoring release and expeditiously place minors ‘in the least restrictive setting appropriate to the minor’s age and special needs’,” the judge Dolly Gee wrote in her ruling.

Donald Trump has made cracking down on immigration a hallmark of his presidency, and administration officials have repeatedly referred to the Flores agreement’s standards as “loopholes” that attract migrants by forcing authorities to release people pending their immigration hearings.

The new regulation would have allowed the administration to hold families in detention centers until their cases are decided, a process that can take months or years. It had been due to go into effect next month.

In a court hearing in Los Angeles on Friday, Gee asked the justice department attorney August Flentje how he could argue that the new regulations were not inconsistent with the terms of the Flores agreement.

“Just because you tell me it is night outside, doesn’t mean it is not day,” Gee said.

Lawyers for the Trump administration are expected to appeal.