LOS ANGELES — A federal judge on Monday ordered the government to transfer all but the most troubled migrant children who have been separated from their families out of an immigration facility in Texas that is alleged to use psychotropic drugs on its wards.

U.S. District Judge Dolly Gee found conditions at the nonprofit Shiloh Treatment Center, in Manvel, near Houston, in violation of a 1997 settlement, called Flores vs. Reno, requiring immigration officials to place detained minors "in the least restrictive setting appropriate to (each Class Member's) age and special needs."

A class-action lawsuit filed on behalf of children at Shiloh in April alleged that children being held in facilities like Shiloh are almost certain to be administered psychotropic drugs like Prozac regardless of their conditions and without their parents' consent, it says. The suit alleges that the drugs are a "chemical strait jacket" used to manage trauma preemptively.

Gee ordered Monday that all children involved in the suit be removed from the Shiloh facility "unless a licensed psychologist or psychiatrist" determines that a particular child "poses a risk of harm to self or others."

And she ordered the government to seek consent before giving psychotropic drugs to any detained migrant child. Without consent, the facility may administer such a drug only in an emergency or under a court order, she said.

Shiloh Treatment Center in Manvel, Texas. A class-action lawsuit alleges that migrant children detained there are given psychotropic drugs regardless of whether they're needed. Google Maps

Gee separately ruled on Friday that an independent monitor should be appointed to assess conditions at facilities like Shiloh.

Carlos Holguin, general counsel for the Center for Human Rights & Constitutional Law, the Los Angeles legal nonprofit that brought the motion to enforce the 1997 settlement at Shiloh, didn't immediately return messages seeking comment. The Justice Department had no immediate comment.

Jess Morales Rocketto, a leader of Families Belong Together, a coalition of organizations opposing the Trump administration's zero-tolerance enforcement at the border, said: "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 Rocketto, political director of the National Domestic Workers Alliance.

Most migrant children crossing the border alone are housed in so-called non-secure private facilities under government contracts while their cases are adjudicated. Some children, however, are placed in more strictly guarded "secure facilities" if they meet certain criteria.

Gee wrote Monday that many of those children are being held in facilities where security is more restrictive than is justified.

She specifically ordered the government to transfer any class member who is held in a "secure facility" if the child is being held there solely because the government believes he or she "may be chargeable" with a crime (as opposed to "is chargeable," she wrote) or who simply reports gang involvement or displays gang affiliation in the absence of any proof of a specific offense.

Citing allegations that at least one detainee at Shiloh had been denied access to drinking water, she ordered the facility to drop any security measures "that are not necessary for the protection of minors or others" — including denial of water and access to telephones for private conversations.

While Shiloh is in Texas, the case was heard in Los Angeles because the Flores settlement is overseen by the federal court there.