Migrant children detained at the U.S.-Mexico border should be placed in shelters operated by the Department of Health and Human Services shelters rather than in hotels, a federal judge ruled Friday.

The controversial practice of using hotels as long-term shelters takes away “fundamental humanitarian protections” from the children, U.S. District Judge Dolly Gee in California's Central District said.

Children can still be kept in hotels for short stays of one or two days, her ruling says.

At the HHS shelters, the children would have access to legal services and a chance to be placed with relatives in the U.S., the judge added.

US DETAINING MORE MIGRANT CHILDREN IN HOTELS DESPITE OUTCRY 

The U.S. has expelled 148,000 immigrants at the border under a new March emergency declaration that says those crossing the U.S.-Mexico border illegally could help spread the coronavirus. Critics of the declaration claim the administration is using the pandemic as an excuse to sidestep federal anti-trafficking laws and asylum protections.

The government “cannot seriously argue in good faith that flouting their contractual obligation to place minors in licensed programs is necessary to mitigate the spread of COVID-19,” Gee wrote in her ruling.

The Trump administration to date has put up at least 577 unaccompanied migrant children -- some as young as one year old -- in hotels to prevent them from being allowed to stay in the U.S.

The children are then usually put on flights out of the country.

At the same time, more than 13,000 beds in HHS shelters– where children could get legal help, education and a chance to stay in the country – remain empty.

Gee’s ruling orders the administration to stop placing children in hotels by Sept. 15 and send them to HHS shelters instead, including those whose parents crossed illegally.

It also gives lawyers who work with immigrant youths access to the children that the government is trying to expel under the emergency declaration.

Government lawyers indicated they may seek an appeal to the decision.

Private contractors at the hotels monitor detained children and families around the clock and generally don’t allow people to leave their rooms. Families that have been detained in the hotels have told The Associated Press that they are served regular meals, but that the telephones have been removed from their rooms.

A Haitian man claimed that a private contractor told his wife and him to suck on ice cubes before their flight back to avoid setting off any airport temperature checks. He said he was also told to give one to their baby daughter. They were never allowed to seek asylum.

A man holds up his 1-year-old daughter at his house in Port-au-Prince, Haiti, Tuesday, Aug. 25, 2020. (Associated Press)

U.S. Immigration and Customs Enforcement denied the claim.

The Trump administration has argued that Gee doesn't have the authority to stop the use of hotels because the children it is expelling fall outside a longstanding court settlement known as the Flores agreement, which requires minors to be held in facilities with certain standards, including sanitary facilities, medical care, supervision and contact with family members. The administration has previously appealed several of Gee's rulings targeting detention practices.

Leecia Welch, an attorney at the National Center for Youth Law, called the ruling “a resounding victory for immigrant children.”

CLICK HERE TO GET THE FOX NEWS APP

“The government’s attempt to use the pandemic as a subterfuge to carry out its ruthless immigration agenda clearly violates the rule of law and human decency,” she said.

The Associated Press contributed to this report.