A federal appeals court in Illinois ruled Thursday the Trump administration could not withhold public safety grants from cities solely because those cities had so-called "sanctuary" policies protecting illegal immigrants.

The decision by a three-judge panel of the 7th U.S. Circuit Court of Appeals in Chicago said the administration exceeded its authority in establishing a new condition for cities to qualify for the grants. It upheld a temporary injunction issued by a lower court judge this past September.

Justice Department spokesman Devin O'Malley said the department "believes it exercised its authority, given by Congress, to attach conditions to ... grants that promote cooperation with federal immigration authorities when the jurisdiction has an illegal alien who has committed a crime in their custody."

DHS REVEALS DOZENS OF MS-13, OTHER GANG MEMBERS RELEASED BY 'SANCTUARY' POLICIES

The Trump administration in July imposed a condition that cities receiving public safety grants must agree to inform federal agents when immigrants in the country illegally are about to be released from police detention. Chicago was among several cities that sued the administration.

U.S. District Judge Harry Leinenweber granted Chicago's request for a temporary nationwide injunction. All three judges agreed Thursday with Leinenweber, meaning the nationwide injunction would remain in force. But one judge, Daniel Manion, issued a partial dissent, saying that the ruling should apply to Chicago only.

"An injunction, particularly a preliminary injunction, is an extreme remedy," Manion wrote. "A nationwide preliminary injunction is more extreme still. One should only be issued where it is absolutely necessary, and it is far from absolutely necessary here."

The Justice Department highlighted Manion's dissent in part, adding that "[n]ationwide injunctions allow a single federal district judge to set policy by ordering relief outside the scope of the particular case. Many in the legal community have expressed concern that the use of nationwide injunctions is inconsistent with the separation of powers, and that their increased use creates a dangerous precedent.

"We will continue to fight to carry out the Department’s commitment to the rule of law, protecting public safety, and keeping criminal aliens off the streets to further perpetrate crimes."

Hours after the ruling came down, Trump reacted to a recent Department of Homeland Security report that claimed dozens of gang members were shielded from deportation and released from prison under "sanctuary" policies.

"Sanctuary Cities released at least 142 Gang Members across the United States, making it easy for them to commit all forms of violent crimes where none would have existed," Trump wrote. "We are doing a great job of law enforcement, but things such as this make safety in America difficult!"

Fox News' Bill Mears and Madelin Fuerste contributed to this report.