A court in the United States has ordered the government to swiftly release immigrant children held at detention centres, affirming a July ruling that said some minors who crossed the border illegally were being detained in violation of a long-standing settlement.

The ruling on Friday by US District Judge Dolly Gee in Los Angeles gave the administration of President Barack Obama until October 23 to comply with her order to release hundreds of unauthorised immigrant children, and in some cases their mothers, "without unnecessary delay".

Gee's ruling comes amid debate by US presidential candidates over illegal immigration and follows an influx of immigrants from Central America across the US-Mexico border.

Last year, more than 68,000 children travelling without a parent entered the US. The federal government has held unaccompanied children, or children caught with a parent, in special facilities.

The federal government has also taken steps to release unaccompanied immigrant children from border detention centres, often to a family member living in the US.

Last month, Gee ruled the Department of Homeland Security was keeping children at detention centres in violation of a 1997 class-action settlement that said juveniles under the age of 18 cannot be held for more than 72 hours.

If a parent was caught with his or her child, authorities could justify keeping the adult in custody if the person is a "significant flight risk" or poses a safety concern, the ruling said.

According to the US immigrant rights group Human Rights First, detention of children cost a daily average of $343 per person [Al Jazeera English]

The ruling was seen as a defeat for US immigration authorities, who in court filings argued releasing undocumented immigrant children encourages families in Central America to undertake the dangerous journey north.

US officials are holding 1,400 parents and children at three centers, according to the Los Angeles Times.

Gee called conditions a the family detention centres - two in Texas, one in Pennsylvania - "deplorable" and said in some cases children were kept in crowded rooms for days without places to sleep.

According to the US immigrant rights group Human Rights First, detention is not only harmful to children and families, but also expensive to taxpayers, costing a daily average of $343 per person.

Source: Al Jazeera and agencies