A federal judge has rejected a rule by the Trump Administration that would put an end to the Flores Settlement Agreement, which would have allowed for the indefinite detention of migrant children.

On Sept. 27, Judge Dolly Gee of the Central District of California, who oversees the terms of the Flores Settlement, decided the Trump Administration’s decision to terminate the settlement violated the terms of the agreement — a 1997 federal court agreement that limited the length of time migrant children could be kept in detention to 20 days.

“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,'” wrote Gee in a court order on the decision.

The Trump Administration had on Aug. 21 announced plans to end the Flores agreement.

The change allowed migrant families to be detained indefinitely, beyond the existing 20-day limit for holding children.

“Today, the government has issued a critical rule that will permit the Department of Homeland Security to appropriately hold families together and improve the integrity of the immigration system,” Acting Secretary of Homeland Security Kevin McAleenan said in an Aug. 21 statement.

“This rule allows the federal government to enforce immigration laws as passed by Congress and ensures that all children in U.S. government custody are treated with dignity, respect, and special concern for their particular vulnerability.”

The news drew immediate backlash from immigration lawyers and advocates. “It’s cruel beyond imagination,” RAICES, a nonprofit that provides legal services to immigrants, said in a tweet.

Here’s what to know about the Flores agreement:

What is the Flores agreement?

The 1997 Flores v. Reno settlement stemmed from a 1985 lawsuit over the treatment of a 15-year-old migrant from El Salvador, Jenny Lisette Flores, and three other minors after they were detained by immigration authorities while trying to enter the United States.

Their lawsuit alleged they had been subjected to strip searches and body cavity searches, and were detained with unrelated adults. The lawsuit also said they were denied educational instruction, medical examination, “adequate and appropriate” recreational activity and visitation from family and friends.

It took aim at a 1984 policy implemented by the Western Region of the Immigration and Naturalization Service, which called for detaining juveniles “indefinitely” — until their parent or legal guardian could come pick up the child in person and be interrogated by immigration authorities. This was something many undocumented immigrants were afraid to do, worried it would lead to deportation.

The Flores agreement, settled in 1997, established that the government must release children within 20 days, even if to a sponsor in the community or another type of program.

The Trump Administration and Flores

The Trump Administration’s policy of separating families at the border last year renewed debate over Flores. In September 2018, the Trump Administration proposed a plan to withdraw from the agreement and allow families to be detained indefinitely while their immigration cases proceed.

At the time, an attorney for the ACLU Immigrants’ Rights Project said the changes were “nothing less than a roadmap for keeping children and families locked up indefinitely.” The president of the American Immigration Lawyers Association said the changes would “threaten the safety and wellbeing of children supposedly under the care of the federal government.”

“Stripping away these fundamental humanitarian protections will only benefit private prisons and waste billions in taxpayer money to jail children and their parents,” Anastasia Tonello, president of the American Immigration Lawyers Association said in September.

The changes announced on Wednesday come just a week after a panel of judges for the Ninth U.S. Circuit Court of Appeals dismissed an appeal by the government in a suit over the conditions at border facilities that was based on the requirements established by Flores.

Trump, who has prioritized a crackdown on immigration, has complained about the Flores agreement during the past year, calling it “a disaster for our country.” But his new policy is now expected to bring new legal challenges.

What are the likely next steps?

The proposed regulations were expected to go into effect two months after its announcement.

During that time, lawyers immediately challenged the Trump administration in the same California court that has been overseeing the Flores Agreement, Lee Gelernt, the deputy director of the ACLU’s Immigrants’ Rights Project, tells TIME at the start of the Trump Administration’s decision. “We hope that [the judge] will strike down the regulations before they even go into effect.” (While the ACLU has not filed suit yet, Gelernt says it will “certainly be prepared to assist in whatever way is necessary.”)

“The medical consensus is that long term institutionalization of children causes serious harm,” Gelernt says.

Wendy Young, president of the advocacy organization Kids in Need of Defense, tells TIME that if the regulation is anything like the government’s proposal from last September, “there’s a very strong chance” that the court would reject it.

One critique the court had of the Trump administration’s initial proposal, Young notes, was that facilities housing families would not be licensed. She says the new proposal includes a government run licensing project, but adds, “That’s basically the fox watching the hen house.”

Young also notes that detention is extremely expensive, and finding the brick and mortar facilities that are suitable and appropriately licensed is “going to be extremely difficult to do.”

A statement from RAICES echoes this concern: “Under the Trump administration at least seven children have died in detention. Immigration officials keep children in filthy, unsafe conditions, and children are denied legal access, education, and continue to be separated from their families.”

Write to Katie Reilly at Katie.Reilly@time.com and Madeleine Carlisle at madeleine.carlisle@time.com.