In a 24-page order, Gee stressed that the 1997 consent decree was a contract between both parties and could not be superseded at the request of a single party.

“The blessing or the curse — depending on one’s vantage point — of a binding contract is its certitude,” Gee said in the order. “Defendants cannot simply ignore the dictates of the consent decree merely because they no longer agree with its approach as a matter of policy.“

The decision represents a legal setback for the Trump administration, albeit a predictable one. Gee, an appointee of former President Barack Obama, rejected another Trump administration attempt last year to alter the settlement agreement.

A Justice Department spokesperson said in a written statement that the department was “disappointed“ with the outcome.

“The Trump administration will continue to work to restore integrity to our immigration system and ensure the proper functioning of the duly enacted immigration laws,” he said.

Trump officials have argued the 20-day detention limit — applied to migrant families by Gee in 2015 — has encouraged Central American parents to trek north with their children. Border Patrol arrested a record number of migrant families in the spring, although traffic has subsided in recent months.

Peter Schey, a lead attorney representing plaintiffs in the lawsuit, said it was clear that the new Trump detention regulations would not fulfill the terms of the Flores agreement.

“President Trump would fire the whole team of lawyers at DHS if they came up with regulations that were consistent with the settlement,” Schey said. “He wants to detain children indefinitely.”

The court setback means the administration will continue to be bound by the 20-day limit on family detention, pending the outcome of any possible appeal.

One point of contention in Friday’s ruling was a Trump administration attempt to allow Immigration and Customs Enforcement to create its own licensing scheme for family detention centers. The Flores agreement requires the centers to be state-licensed.

Gee said placing children in ICE residential centers would be “patently inconsistent“ with the agreement and not adequately allow for monitoring by an independent child welfare agency.

She also blasted the regulation’s characterization of existing family detention centers as “non-secure” facilities that would permit lengthy detentions of children with their parents.

“In Kafkaesque fashion,“ she wrote, “the new regulations declare that [family residential centers] are non-secure (and always have been), regardless of whether they are or ever have been, in fact, non-secure.”

While the ruling could hinder Trump administration efforts to step up enforcement against migrant families, DHS continues to implement a range of actions to discourage traffic to the southwest border.

Acting Homeland Security Secretary Kevin McAleenan said this week that immigration authorities would stop releasing most migrant families caught at the border into the interior of the U.S., ending what Trump has called “catch and release.” Instead, McAleenan said the families would be processed for rapid removal or sent to Mexico if they have requested asylum.

In recent months and weeks, the Trump administration also has brokered asylum deals with Guatemala, El Salvador and Honduras that would require those countries to accept asylum seekers who pass through their territory en route to the U.S. Each of those agreements requires additional steps before taking effect.

Earlier this month, the Supreme Court allowed the administration to implement a sweeping ban on asylum seekers who transit through another country on their way to the U.S. if they failed to request protection in that place.