PHILADELPHIA—A federal judge has ruled in favour of Philadelphia in its lawsuit against the federal government for withholding grant funding in response to how the city deals with immigrants in the country illegally.

U.S. District Judge Michael Baylson issued a 93-page memo Wednesday, saying the conditions placed on the city by the federal government in order to receive the funding are unconstitutional, “arbitrary and capricious.” He also wrote that Philadelphia’s policies are reasonable and appropriate.

Philadelphia has said as a “sanctuary city” it will only turn over immigrants to Immigration and Customs Enforcement if they have a warrant signed by a judge. The city was fighting federal efforts to block funding as a result of the policy.

A federal appeals court in April sided with Chicago in a similar dispute.