A federal judge on Monday ordered the Trump administration to transfer all undocumented immigrant minors out of a detention facility in Texas due to allegations of abuse and over-medication against the children.

U.S. District Judge Dolly Gee ruled that conditions at the Shiloh Residential Treatment Center in Manvel, Texas, violate a 1997 court settlement that dictates how the government must care for minors who entered the country illegally on their own or were separated from their parents.

Gee ruled that employees at the facility, which is contracted and overseen by the Department of Health and Human Services, administered psychotropic drugs to minors without their parents' consent, kept some minors in overly-restrictive confinement, and forbade minors from making private phone calls. The department says Shiloh, and other facilities like it, are "secure" facilities that are needed to detain minors with mental health problems or who pose other safety risks.

Gee ruled that facility operators often went overboard in their detainment and punishment of the minors, in one case repeatedly denying water to a boy and then abusing him when he "insisted upon leaving his room for that purpose."

The judge did not shut down the facility, but ordered a series of changes to improve living conditions for the children.

Operators must "comply with all Texas child welfare laws and regulations," including a requirement that a legal guardian must sign off on any psychotropic drugs given to the child. The facility must allow for private phone calls and allow minors more free time. And HHS officials must transfer all minors out of Shiloh unless a licensed psychiatrist or psychologist examines each one and determines that they pose a risk to themselves or others.

The ruling follows a separate ruling from Gee on Friday when she appointed an independent monitor to oversee conditions at facilities that house immigrant minors.

The treatment of those minors has been at the heart of another lawsuit in which the Trump administration has been forced to reunite about 1,500 children who were separated from their parents along the border. The ACLU says the Trump administration missed that deadline by failing to reunite hundreds of other minors who were separated, a charge that U.S. District Judge Dana Sabraw is expected to rule on later this week.

Monday's ruling from Judge Gee was a relief to the immigration advocacy groups that have long complained about the conditions of minors in custody, especially at the Shiloh facility.

"A federal court has now confirmed what we already knew: children are suffering abusive treatment and cruel and inhumane conditions in government detention centers. Children belong with their families, not scared, alone, and subject to abuse in prison-like conditions," said Jess Morales Rocketto, political director of the National Domestic Workers Alliance. "Appointing an independent monitor and removing children from the cruelest of these facilities is a good first step, but it is not nearly enough."

On its website, Shiloh officials published a statement pointing out that in recent weeks the facility has been "visited, audited, and investigated" by multiple state agencies, the federal Office of Refugee Resettlement, and consulate representatives from Guatemala, El Salvador and Mexico.

"All of the widely distributed allegations about Shiloh were found to be without merit," the statement read. "The children have been found to be properly cared for and treated."