When 26 states filed suit against the Department of Homeland Security (DHS), attacking the Obama administration’s immigration policies, few gave them much chance of success. The executive branch has wide latitude in the enforcement of immigration laws, even if those laws are a patchwork mess.

That’s why it was a surprise when District Court Judge Andrew Hanen of the Southern District of Texas issued an injunction against DHS, forbidding it from implementing its own regulations. Politically, the decision was not so shocking—Judge Hanen is known to be an outspoken conservative. But legally?

In fact, the surprise grows the more you read the 123-page opinion. Despite conservatives’ professed dislike for activist judges, the opinion is activist jurisprudence par excellence.

The opinion is full of highly politicized statements like “there can be no doubt that the failure of the federal government to secure the borders is costing the states—even those not immediately on the border—millions of dollars of damages each year.” Not only is there “doubt” about this Republican talking point—there’s a heated political controversy about it.

Similarly, the court states, as fact, contentious claims like “the states lose badly needed tax dollars each year due to the presence of illegal aliens.” Actually, there’s significant economic data that “illegal aliens” help economic growth. Just ask the citrus industry in California, which depends on the labor of undocumented workers.

Even the rhetoric is partisan. There are no “undocumented” people in Judge Hanen’s opinion; only “illegal aliens.” It’s also a very messy opinion—misspelling the name of Supreme Court Justice John Paul Stevens several times, for example.

The court’s legal reasoning is equally sketchy. At issue is DHS’s expansion of DACA, the “Deferred Action” program that allows undocumented immigrants to stay in the United States for up to three years. For the Obama administration, the expansion is an exercise of discretion. For the states (all red, except Maine and Ohio), it’s a new set of laws with disastrous consequences.

The first legal question is one of standing. As the court noted, states do, in fact, bear the brunt of federal actions—or inactions—on immigration. (Of course, is there any federal action that doesn’t affect states?) But how do state governments have legal standing to challenge a set of administrative policies?

This question took the court fifty pages to parse, likely because Judge Hanen wanted to find as many possible ways to sustain this bizarre opinion on appeal. And so it found three separate bases for the states having standing: the expansion of DACA will cost the states money (for example, in granting drivers licenses to all those new “illegal” residents), it might hurt its citizens economically, and that the federal government has abdicated its responsibility to enforce the law.

This last form of standing—“standing created by abdication”—is the most novel. The argument is that the federal government has sole authority to enforce immigration laws, but has chosen not to do so.

DHS argues that it is using its discretion to allocate insufficient resources. The states, however, argue that it’s just not doing its job.

Amazingly, the court agreed. “The states assert that the Government has abandoned its duty to enforce the law. This assertion cannot be disputed.”

It cannot? Let’s try this hypothetical: A government is charged with protecting the public safety. Recognizing that it can’t put a cop on every single corner in the city, it allocates its police presence in the way it deems best. Is that “abandoning its duty to enforce the law”? Must a law be enforced in such a way that it is always enforced, all the time, everywhere? Even though we all know that that is completely impossible?

Or how about rail crossings, like the one in upstate New York where six people tragically died last week? Municipalities could spend several million dollars per crossing to replace them with overpasses. Are they abdicating their duty to protect safety by not doing so?

If any allocation of resources represents an abdication of enforcement, well, anything goes.

After a lengthy procedural section on reviewability, the court finally turns to the central legal questions in the case around page 87, when it distinguishes between non-enforcement of a law on the one hand, and the actual DACA program on the other:

Non-enforcement is just that—not enforcing the law. Non-enforcement does not entail refusing to remove these individuals as required by law and then providing three years of immunity from that law, legal presence status, plus any benefits that may accompany legal presence.

That, really, is the court’s central point. The expanded DACA, it holds, is not non-enforcement; it’s a new legal regime, with new rights and benefits.

Here, President Obama bears some responsibility. As Judge Hanen notes several times, he said that he was acting to “change the law.” That does make it hard for DHS to now claim that it’s only enforcing the law within its discretion. Although President Obama’s statement is not formally under review, it sure doesn’t help.

Yet here, too, the court’s position is not legally tenable. On the one hand, Judge Hanen notes with outrage that DHS “discretion” could allow the government to grant legal residency to all 11 million “illegal” immigrants—something the administration has strenuously denied. On the other hand, the judge complains that DHS’s non-whole-hog policy is creating a new legal regime.

So, doing nothing is bad, and doing something is bad. The only not-bad thing is doing everything: deporting “illegals” without creating any regime for those who aren’t immediately deported.

The court’s legal argument ends up in the same place as its standing argument: the government actually has no discretion at all.

“The Government is charged with the duty of removing them,” the opinion says. “DHS is tasked with the duty of removing illegal aliens.”

And that’s that.

Of course, this is only a preliminary injunction, not a final ruling on the merits. And DHS has already said that it will appeal. But this kind of activist judging is nonetheless jarring. It would be interesting to apply Judge Hanen’s reasoning to environmental cases, for example—giving the EPA no discretion in allowing polluters time to get their factories in line, or conform to clean water standards, or whatever.

But then, this is opportunistic activism. After all, earlier this month, Alabama’s Chief Justice decried a district court judge for “imposing” same-sex marriage on unwilling Alabamans, and conservatives seemed to agree. Now a district court has taken sides in a political debate, and conservatives are breaking out the champagne.

See you on appeal.