A federal judge in California on Saturday found that the Trump administration has not taken sufficient measures to safeguard the health of detained migrant children during the coronavirus pandemic, calling detention facilities "hotbeds of contagion."

Citing the "unprecedented threats" posed by the coronavirus crisis, Judge Dolly Gee of the U.S. District Court in Los Angeles ordered officials to make every effort to release detained children "without unnecessary delay," a requirement established through the landmark Flores Settlement Agreement, which governs the care of minors in U.S. immigration custody.

If the children are not promptly released, Gee said the administration has to justify their continued detention amid a global pandemic that has killed more than 32,100 people, including more than 2,200 in the U.S.

Get Breaking News Delivered to Your Inbox

"We think President Trump is unnecessarily detaining thousands of immigrant children in violation of the Flores settlement that we reached with the government in 1997, and has done precious little to protect them from the dangers of coronavirus infection," Peter Schey, president of the Center for Human Rights and Constitutional Law, told CBS News.

Last week, Schey, one of the two attorneys who filed the original lawsuit that prompted the Flores agreement, and his group asked Gee to require officials to promptly release migrant children who are not flight risks and who don't pose a danger to themselves or others. Gee, who has overseen litigation surrounding the agreement for years, partially granted the request, ordering the government to say by April 10 why she shouldn't order them to stop detaining children who could be released to family members in the U.S.

Gee said she did not order the "en masse" release of detained minors because of current coronavirus-related travel restrictions, as well as the possibilities of "contagion via public transportation" and of "introducing healthy children to homes where they could be at a higher risk of infection." But she also noted that experts have advocated for reducing the population in detention facilities to "lessen the resource constraints and likelihood of overwhelming contagion in the less-crowded facilities."

Prolonged detention of minors, especially during a public health crisis, could also cause physiological damage, Gee said.

"For migrant children in detention, who are already more likely to have mental health concerns or may be separated from their family members, the trauma of undergoing solitary quarantine for the virus or simply not receiving adequate information about the potential for infection is likely to exacerbate existing mental health concerns," the judge wrote in her order.

Saturday's order applies to the approximately 3,400 unaccompanied migrant children in custody of the Office of Refugee Resettlement (ORR), as well to hundreds of minors detained with their families in three U.S. Immigration and Customs Enforcement (ICE) facilities in Texas and Pennsylvania. Both agencies said they were reviewing Gee's order.

Four children in ORR custody and two men in ICE custody have already tested positive for the coronavirus. More than a dozen workers in detention facilities overseen by the two agencies have also been infected.

Apart from finding ICE and ORR could be violating the Flores agreement because of "their failure to release minors to suitable custodians in a prompt manner," Gee said conditions in ICE detention centers for families with children could breach the settlement's requirement of "safe and sanitary" accommodations. She said ICE's guidance to curb the spread of the virus in its facilities "appears deficient" because it does not address "social distancing, increased personal hygiene, or increased testing and medical care." Gee also cited reports of families in ICE detention centers remaining in close proximity to each other.

When it came to ORR's response to the pandemic, Gee said the agency appeared to be complying with the "safe and sanitary standard" by providing minors in its custody "safe accommodations and medical care." The refugee agency has taken a series of measures in response to the public health crisis, including requiring all children to undergo temperature checks twice a day and halting placements of minors in shelters in California, New York and Washington.

Through her order, Gee also said the administration must allow independent monitors to inspect all detention facilities and provide the court and the advocates in the case with information about children detained in California, Illinois, Louisiana, Massachusetts, Michigan, New Jersey, New York and Washington — the states with the most confirmed coronavirus cases.

Schey said Saturday's order, although limited in scope, is a victory for detained children and their advocates.

"We feel thankful that the federal judiciary has far greater concern for the health and safety of children than the president seems to have," he said. "We think this could save children's lives and protect the safety of hundreds of staff who work at these detention facilities."