The White House has labelled "bananas" a ruling that blocks President Donald Trump's order barring funding for cities that shelter illegal immigrants.
A San Francisco judge has placed January's executive order in limbo, but the White House is vowing to appeal.
San Francisco and Santa Clara County sued in February.
The Trump administration has warned so-called sanctuary cities they could lose federal funds if they do not co-operate with federal immigration officials.
On Tuesday, Judge William Orrick issued a temporary injunction against the presidential order as the case continues in the courts.
"It's the 9th Circuit going bananas," White House chief of staff Reince Priebus said, in reference to the San Francisco-based appeals court, which conservatives often accuse of liberalism.
Mr Trump's measure cast doubt on the transfer of some $1.2bn (£940m) for San Francisco and $1.7bn to Santa Clara County, home to many Silicon Valley communities.
It is another legal defeat for President Trump in his efforts to curb immigration - his plan to curtail travel from seven Muslim-majority nations was twice blocked in federal courts.
Lawyers for the federal government had argued in the sanctuary cities case that only funding related to law enforcement would be withheld.
But Judge Orrick said any doubt about the scope of the "vague" order was erased by public comments made by President Trump, such as those calling the measure a "weapon" to use against jurisdictions that disagree with his immigration policies.
He accused the Trump administration of a "schizophrenic approach" to the order.
The 49-page court ruling added that the plaintiffs challenging President Trump's order are likely to succeed in proving the order unconstitutional.
"Federal funding... cannot be threatened merely because a jurisdiction chooses an immigration enforcement strategy of which the President disapproves," the judge wrote.
However, Judge Orrick's ruling allowed the justice department to follow through with threats made to nine cities last week to cut specific programme grants if they do not adequately co-operate with federal immigration officers.
In a press release last week, the department accused sanctuary cities of "crumbling under the weight of illegal immigration and violent crime".
There are several sanctuary cities across the US, including Mr Trump's home of New York.
New York's Mayor Bill de Blasio praised Tuesday's ruling, saying the president went beyond his authority to cut funding to cities that "don't share his illogical and unconstitutional desire to scapegoat immigrants".