A federal judge has struck down a key Obama administration immigration policy, demanding the release of children from family detention facilities “without unnecessary delay.” Judge Dolly M. Gee gave federal officials two months to comply with her order, meaning they will have until Oct. 23.

In July, Gee said the Obama administration had violated a key 1997 settlement that governs the treatment of children who enter the United States illegally or seek asylum in the country. On Friday, the Los Angeles-based judge rejected a request from the government to reconsider that ruling and ordered the release of children held at family detention facilities to a parent or other relative in the United States. In her order, Gee said that children should not be held for more than 72 hours unless they pose a significant flight risk or are a danger to themselves and others.

Immigrants' rights advocates cheered the move.

Peter Schey, executive director of the Center for Human Rights and Constitutional Law, told the Associated Press that the order “will protect refugee children and their mothers from lengthy and entirely senseless detention.”

Lawyers for the government may appeal the decision, but have not yet indicated they plan to do so. They had argued that Gee’s ruling in July would fuel a wave of illegal immigration into the United States.

The decision strikes at the core of a major expansion in detention facilities that began last year after an influx of undocumented immigrants, mostly from Central America, many of them fleeing gang violence. The administration is now holding roughly 1,400 parents and their children at three centers in Texas and Pennsylvania, where critics have bemoaned conditions.

A report released this month by human rights nonprofit group Human Rights First found children at the facility in Pennsylvania showed “symptoms of depression, behavioral regression and anxiety.”

Gee appears to sympathize with some of those critiques. Last month, she called conditions at the detention centers “deplorable” and said they failed to to “meet even the minimal standard.”

Nevertheless, as the New York Times noted, Gee appeared to give federal authorities some wiggle room on the 72 hour requirement. She said that holding women and children for up to 20 days “may fall within the parameters” of the critical 1997 settlement if the administration can demonstrate there is a new influx of immigrants.