(Reuters) - A federal court judge in California on Monday blocked an executive order from President Donald Trump to deny some federal grants to so-called sanctuary cities, undermining the administration’s crackdown on illegal immigration. The judge, who blocked the order provisionally in April, issued a permanent injunction in the suit brought by the city and county of San Francisco and Santa Clara County, which said the order was unconstitutional. “The Counties have demonstrated that the Executive Order has caused and will cause them constitutional injuries by violating the separation of powers doctrine and depriving them of their Tenth and Fifth Amendment rights,” U.S. District Judge William Orrick for the Northern District of California wrote in his order.  Trump issued the order in January, shortly after he was inaugurated, slashing funding to jurisdictions that refuse to comply with a statute that requires local governments to share information with U.S. immigration authorities. As part of that policy, the Justice Department has sought to punish cities and other local jurisdictions that have joined a growing “sanctuary” movement aimed at shielding illegal immigrants from stepped-up deportation efforts. “The district court exceeded its authority today when it barred the president from instructing his cabinet members to enforce existing law,” Department of Justice spokesman Devin O’Malley said in a statement. “The Justice Department will vindicate the president’s lawful authority to direct the executive branch.” The department has already appealed the judge’s prior ruling from April. The Trump administration contends local authorities endanger public safety when they decline to hand over for deportation illegal immigrants arrested for crimes. Dozens of local governments and cities, including New York, Los Angeles and Chicago, have joined the growing “sanctuary” movement. Supporters of the sanctuary policy argue enlisting police cooperation in rounding up immigrants for removal undermines communities’ trust in local police, particularly among Latinos. The Justice Department is concerned about localities’ compliance with U.S. Immigration and Customs Enforcement requests to detain people up to 48 hours beyond their scheduled release time so that immigration officials can pick them up. Some cities say they will only honor such requests when  accompanied by criminal warrants, and that compliance is voluntary and not required under the statute. Chicago also sued the federal government in August over the threats of funding cuts by the Justice Department. A federal judge sided with the city in September and issued a preliminary injunction barring the U.S. government from denying the public-safety grants.  