One thousand undocumented mothers and children currently detained in immigration centers in Texas and Pennsylvania could be freed imminently at the order of a federal judge, unless the US government can avert the crisis in its immigration policy over the next 10 days.

Emergency talks were under way in Washington on Monday between US immigration officials and attorneys representing hundreds of children who are being held in detention allegedly in violation of child protection laws. Unless agreement can be reached between the two sides by 24 May, the families are likely to be released upon order of the courts, punching a large hole in the Obama administration’s deterrent approach at the border.

The Department of Homeland Security has argued that detaining families was a necessary response to last summer’s extraordinary “surge” in the number of children – some unaccompanied, others with their mothers – who tried to cross into the US having fled violence in Central America. But the three detention centers, in Dilley and Karnes City in Texas, and Berks County in Pennsylvania, have since then been inundated with complaints over their treatment of children.

A Guardian investigation of the Berks County residential center based on interviews with former residents and their lawyers identified a number of serious complaints, including:

• an ongoing criminal prosecution of a former Berks guard who has been charged with abusing his position to have sex with a detained mother;

• allegations of poor medical treatment that saw sick children, including a three-year-old girl who was throwing up blood, being advised to “drink more water”;

• a mother and her children as young as three years old placed in a contained room overnight that families likened to solitary confinement;

• alleged inadequate treatment to alleviate severe depression and other conditions among the 43 children held at the facility. Ten have been deemed officially to have mental illnesses and at least one has autism.

Some of the minors in the Berks center have been held for more than a year, and others are younger than one year old, yet they have been detained in conditions that their lawyers say clearly breach child protection rules recognized since 1997.

Neither side of the negotiations would talk to the Guardian, citing a judge’s order that imposes secrecy on the proceedings. But immigration lawyers familiar with the case said that the next 10 days could prove critical in determining the fate of the Obama administration’s hardline approach to undocumented migrant families detained at the Mexican border in 2014.

Bryan Johnson, an immigration law specialist in Bay Shore, New York, said that the case had brought to light the Obama administration’s violation of federal laws. “This shows that the administration has no respect for the law and is intent on detaining individuals until it can deport them regardless of the consequences.”

He added: “This is particularly troublesome when the administration is willing to harm children for the political motivation of keeping a secure border.”

The government’s harsh deterrent approach was adopted after the surge in numbers of border crossers fleeing violence in Honduras and neighboring countries last summer, which saw about 50,000 unaccompanied children, as well as a similar number of “family units” of mothers with children, taken into ICE custody. A “no-release” policy was introduced last July that has seen more than 2,500 women and children held for long stretches at three family detention centers

Last month the mothers currently being detained at Berks wrote a joint letter to the immigration authorities pleading with them for leniency. It said that many of the women had been held for the maximum 13 months “and we think that this confinement is an injustice because we are not delinquents much less criminals”. The mothers urged officials to take into account “the psychological state of the kids as a result of confinement”.

In response to Guardian questions about the lawsuit and the emergency talks, a press secretary for the immigration services said that “as a matter of policy, ICE does not comment on pending litigation”.

But an ICE spokeswoman did respond to detailed questions relating to the Berks center in particular, insisting that it was an “open environment” in which residents have “free movement throughout the grounds during daylight hours”.

Comprehensive medical care was provided at the center throughout an individual’s stay at the facility, the spokeswoman said, with more than 20 medical staff on hand to give 24-hour care. The room into which families complained they had been put in solitary confinement was “only used for medical reasons” and was “never used for disciplinary reasons – the door does not lock”.

As regards the criminal prosecution for sexual assault, ICE immediately responded to the allegations against the Berks County employee and held an internal investigation that led to him being put on administrative leave. ICE was working with the police over the criminal investigation, the spokeswoman said.

Human rights advocates launched the lawsuit against the prolonged detention of immigrant children in the US district court in Los Angeles in February. It said that under the 1997 settlement of Flores v Johnson, children were entitled to be released on bond while their immigration petitions were being considered, while government officials had to treat under-18s in their care “with dignity, respect and special concern for their particular vulnerability as minors”.

The judge hearing the case, Judge Dolly Gee, last month issued a 22-page tentative ruling that indicated her thinking without committing to a firm decision. She gave the government 30 days to reach a settlement with the plaintiffs, or face an imposed court order.

The tentative ruling has been kept sealed at the judge’s bidding, though an account of it has been seen by the Guardian. First reported by McClatchy, it states that all children in custody are entitled to the protections set out in Flores – meaning that they should be released along with their mothers except where doing so would create a safety problem or a risk of flight.

“This is like a nightmare,” said Bridget Cambria, a Reading, Pennsylvania-based lawyer who represents several families in Berks. “Some of these children are being held for more than a year and the impact on them is frightening. Detaining kids with no possibility of release cannot sit easily with our interest in protecting them.”