When an immigrant applies for asylum in the United States — even after entering the U.S. unlawfully — the person is supposed to be released until there is a hearing on the case, according to Carl Shusterman, an immigration attorney based in Los Angeles. If immigration authorities deem it doubtful that the person will appear for the hearing, a bond should be set for his or her release, the attorney added.

Human rights and immigration advocacy groups have condemned the detention of women and children asylum seekers. Many have also criticized conditions at Immigration and Customs Enforcement (ICE) detention centers as unfit for families.

Peter Schey, executive director of the Center for Human Rights and one of the attorneys who brought the suit, said federal officials "know they're in violation of the law."

"They are holding children in unsafe facilities. It's that simple," Schey told The Associated Press. "It's intolerable, it's in humane, and it needs to end, and end sooner rather than later."

Justice Department attorneys did not immediately reply to messages seeking comment on the ruling.

The new lawsuit was brought on by new major detention centers for women and children in Texas that are overseen by the U.S. government but are managed by private prison operators. Together they have recently held more than 2,000 women and children between them after a surge of tens of thousands of immigrants from Central America, most of them mothers with children, many of whom claimed they were fleeing gang and domestic violence back home.

The Justice Department had argued it was necessary to modify the settlement and use detention to try to deter more immigrants from coming to the border after last year's surge and it was an important way to keep families together while their immigration cases were being reviewed, but the judge rejected that argument in Friday's decision.

Gee gave the Department of Justice one week to show cause why she should not enter an injunction that would require the government to comply with the ruling within 90 days.

Since the tentative ruling in April, ICE has vowed to make the facilities more child-friendly and provide better oversight.

Al Jazeera and The Associated Press