David Cole is national legal director of the ACLU, which has sought to join Santa Clara County and San Francisco’s lawsuits against the Trump administration.

States’ rights have long been a rallying cry for conservatives. The Trump administration cited its respect for the states in rescinding Obama administration guidance treating discrimination against transgender students as sex discrimination. Attorney General Jeff Sessions invoked the same principle in questioning federal consent decrees designed to ensure constitutional policing in cities such as Chicago and Baltimore. And when the Supreme Court relied on states’ rights to gut the Voting Rights Act, then-Sen. Sessions applauded the decision, calling it “good news . . . for the South.” In earlier periods, states’ rights arguments were advanced to resist desegregation and federal legislation protecting workers and consumers.

But the Trump administration doesn’t consistently respect the states, and nowhere is that more true than in its attack on “sanctuary cities,” in which it claims that states and cities choosing not to help enforce federal immigration law should be denied federal funding. On Tuesday, a federal court in San Francisco invoked the very federalist principles that President Trump and Sessions celebrate to rule unconstitutional Trump’s executive order denying funding to sanctuary cities, one of the signature initiatives of Trump’s first 100 days. The nationwide injunction, issued by U.S. District Judge William H. Orrick, ruled that Trump violated the rights of state and local governments to make decisions about the deployment of their own resources. The Constitution, the court ruled, mandates that state and local governments be left to make their own judgments about what best serves the safety of their people. Like lawsuits by the states of Washington and Hawaii challenging Trump’s anti-Muslim travel ban, the case demonstrates the value of our federalist system when one party controls the levers of federal power.

[This failure may doom Trump’s presidency before it really begins]

The decision arises out of two cases filed by Santa Clara County, Calif., and San Francisco. Both juridictions determined some time ago that they would decline to enforce federal immigration law, because doing the federal government’s work would directly undermine their ability to maintain public safety. If undocumented immigrants fear that they may be deported any time they approach the authorities, they will be unlikely to come forward as witnesses to crime and unlikely to go to public hospitals for immunizations and other necessary care. For these reasons, many cities have elected not to enforce federal immigration law.

Cities and states have the right to so choose because the 10th Amendment to the Constitution, which preserves state authority, bars the federal government from compelling states to enforce or administer federal laws. The Supreme Court has explained that states must have the ability to make autonomous decisions about deploying their resources, so the federal government cannot “commandeer” their cooperation in carrying out a federal program. That’s a principle conservatives have long championed. But now that they control Congress and the White House, they are less eager to honor its dictates, especially when they protect progressive cities.

Trump’s executive order instructed the attorney general to ensure that “sanctuary jurisdictions” are ineligible for federal funds. San Francisco and Santa Clara County each receive more than $1 billion in federal funds, for all sorts of educational, health, infrastructure and law-enforcement programs having nothing to do with immigration. All of that funding could be at risk if they were declared sanctuary jurisdictions. Trump described the order as “a weapon,” and Sessions said in a news conference that violating the executive order “could result in withholding grants, termination of grants and disbarment or ineligibility for future grants.”

The threats worked in some places. The mayor of Miami-Dade promptly reversed his city’s policy against enforcing federal immigration law except in limited circumstances . But other cities have stood firm.

[We asked you to describe President Trump’s first 100 days. Here’s what you said.]

In the California litigation, Trump’s lawyers barely defended his actions, and instead did all they could to distance themselves from Trump and Sessions’s threats. They argued that the order actually had no legal effect whatsoever, but was merely an exercise of the “bully pulpit” and a directive to enforce existing law. The order should be upheld, they argued, because it was meaningless. As the district court put it, the Justice Department “attempts to read out all of [the provision’s] unconstitutional directives to render it an ominous, misleading, and ultimately toothless threat.” The court rejected that invitation as essentially asking it to rewrite the order, something beyond the court’s power to do.

Instead, the court did what it does have the power to do: It declared the order unconstitutional, primarily because it intrudes on the 10th Amendment rights of state and local governments by conditioning such large amounts of federal funds on carrying out immigration law. In essence, it demanded that Sessions and Trump practice what they preach. Ironically, the most powerful precedent for this holding was the Supreme Court’s 2012 decision invalidating the Affordable Care Act’s requirement that states expand Medicaid coverage as a condition of federal funding.

Federalism and federal courts were both designed as integral elements of our system of checks and balances. Never are they more important than when one party controls the presidency and Congress. The framers hoped that states would resist unwarranted federal encroachments and that federal judges, given independence through life tenure, would uphold constitutional principle against executive overreach. Thus far, to Trump’s dismay, the system seems to be working just as the framers intended.