A federal judge in Los Angeles blocked the Trump administration Friday from enforcing rules that would allow authorities to indefinitely detaining immigrant children with their parents at the U.S.-Mexico border.

At issue is the so-called Flores Settlement Agreement, a 22-year-old consent decree that specifies how long and under what conditions underage immigrants can be detained by the government. The administration sought to withdraw from the 1997 agreement as part of a crackdown on asylum seekers arriving at the southern border.

The agreement forbids holding children in unlicensed detention facilities for more than 20 days. Trump officials have said the agreement incentivizes illegal immigration.

The Department of Homeland Security and the Department of Health and Human Services issued new rules over the summer to end the agreement and allow the federal government to license detention facilities, which would allow longer detention periods for migrant children.

HOUSE REBUKES TRUMP ON BORDER WALL, BUT HE PLANS VETO

But U.S. District Court Judge Dolly Gee expressed skepticism about the government’s arguments, issuing an order concluding that the administration’s proposed rules “fail to implement and are inconsistent with the relevant and substantive terms of the Flores Settlement Agreement.”

"Just because you tell me it is night outside doesn't mean it is not day," Gee told government lawyers.

The government argued it has the discretion to issue new rules to replace the old agreement. But immigrant advocates say the provisions would allow the indefinite detention of children in unlicensed facilities.

BORDER PATROL NABS NEARLY 200 CENTRAL AMERICAN MIGRANTS NEAR NEW MEXICO PORT OF ENTRY

Gee wrote officials "cannot simply ignore the dictates of the consent decree merely because they no longer agree with its approach as a matter of policy."

Attorneys representing immigrant children said the administration was using young immigrants to deter migrants from seeking asylum.

"We will continue vigorously to defend the rights of detained immigrant children," Neha Desai, director of immigration at the National Center for Youth Law, told reporters.

U.S. Rep. Joaquin Castro, D-Texas, who chairs the Congressional Hispanic Caucus, praised the ruling.

“I am pleased that our justice system has stopped the Trump administration plans to indefinitely detain families in prisonlike conditions,” Castro said. “This victory gives us hope and is a reminder to us all — elected officials, immigration lawyers, organizers, and advocates — to keep fighting. Flores is not a loophole — it’s a lifesaving standard that protects the basic rights and dignity of migrant children.”

The Flores ruling came about as a result of a 1980s case in which a girl named Jenny Flores, then 15, was detained with adults by U.S. authorities after she fled El Salvador. Beginning in 1997, the Flores settlement called for migrant children to be sent to care programs after 20 days, be given access to medical treatment and allowed visits with relatives.

CLICK HERE TO GET THE FOX NEWS APP

The Trump administration has enacted several policies aimed at curbing the flow of migrants to the border. Migrants now have to wait in Mexico for their immigration court hearings and anyone passing through a third country on their way to the U.S. must seek refuge there before applying for asylum in America.

Hundreds of thousands of migrants have been detained at the border in recent years as many Central American families flee violence and poverty.

Fox News reporter Ronn Blitzer and The Associated Press contributed to this report.