NEW YORK (Reuters) - A federal judge on Wednesday ordered a U.S. refugee agency to reverse a policy that a New York civil rights group has blamed for excessively long detention of immigrant children in the state.

U.S. District Judge Paul Crotty in Manhattan ordered the Office of Refugee Resettlement (ORR) to abandon its policy of having its director, Scott Lloyd, personally sign off on the release certain children from its custody.

The order was a preliminary injunction in a lawsuit filed in February by the New York Civil Liberties Union (NYCLU). It is not related to separation of parents and children at the U.S.-Mexico border.

“Today the court ordered the Trump regime to end the cruel policy that gratuitously prolonged the separation of immigrant children from their families and upended their lives,” NYCLU Executive Director Donna Lieberman said in a statement. “ORR can no longer keep children detained at the whim of a director who has demonstrated little expertise and less consideration for the well-being of children.”A spokesman for the Department of Health and Human Services, ORR’s parent agency, could not immediately be reached for comment.

Most children taken into ORR custody entered the United States unaccompanied, though the lead plaintiff in the case, identified in court papers as L.V.M., was taken from his home on Long Island by authorities in July 2017 based on reports that he was involved in the violent MS-13 gang. An immigration judge later determined he posed no danger.

Federal law requires that children in ORR custody be placed with loved ones if possible while their immigration cases are pending.

The NYCLU brought its lawsuit on behalf of a class of children in New York who were at some point placed in one of ORR’s most secure facilities. Starting last year, ORR adopted a policy in which Lloyd must personally sign off on the release of those children from custody.

At the time it brought the lawsuit, the NYCLU said the class included more than 40 children.

Crotty wrote in Thursday’s opinion that the policy had been adopted almost immediately after Lloyd was sworn in, “with no record demonstrating the need for change,” violating the federal Administrative Procedure Act.

“This is at the zenith of impermissible agency actions,” the judge wrote.

The ruling came on the same day as the U.S. House of Representatives rejected legislation that would have addressed the crisis of families being separated at the U.S.-Mexico border.