Contrary to reports in the press, Defense Secretary Jim Mattis did not “freeze” or “put on hold” Donald Trump’s ban on transgender people serving in the military.

In fact, Mattis is doing exactly what Trump ordered—and it is the words of those very orders that will doom the anti-trans plan in court.

In a series of tweets on July 26, Trump announced that the military “will not accept or allow Transgender individuals to serve in any capacity.” Then, on August 25, the White House issued a presidential memorandum implementing this new policy.

Sort of. In fact, if you read the memorandum (which few people have apparently done), it actually only changes two parts of current policy. First, it indefinitely suspends the “accession” (i.e. enlistment or drafting) of trans people, which was due to begin on July 1, pursuant to an Obama-era directive issued last year. (More on that in a moment.) Second, the memo prohibits the military and coastguard from paying for trans soldiers’ medical expenses.

In other words, Trump’s bite never matched his bark. The memo did not direct the military to dismiss active-duty trans personnel, as he had earlier promised.

Finally, the memo instructs Mattis to study the issue and provide recommendations—which is exactly what Mattis has said he will now do. The media flurry about Mattis disobeying Trump is simply not true.

But if you read the fine print, you’ll see that—as with the travel ban—Trump has set his own legal mousetrap. Because the exact instructions are that the ban on trans enlistment is set to last “until such time as the Secretary of Defense, after consulting with the Secretary of Homeland Security, provides a recommendation to the contrary that I find convincing.”

That I find convincing?! That kind of rationale may work in authoritarian banana republics, but it’s not going to pass judicial muster. Especially when this new ‘policy’ replaces one that was the result of a yearlong study and a detailed analysis by the RAND Corporation of the effects that trans people would have on military effectiveness and budget. (Answer: next to none.)

That was an actual policy, with concrete data and careful study. And what Trump wants to replace it with? A ban until there’s a “recommendation to the contrary that I find convincing.”

That, like Trump’s recent pardon of the scofflaw sheriff Joe Arpaio, is a demagogic pronouncement directly antithetical to the rule of law.

It is also unconstitutional.

The best analogue to this whole affair is—stay with me for a moment—last year’s Supreme Court case on Texas’s abortion restrictions, Whole Women’s Health v. Hellerstadt. The central question in that case was whether there was any plausible scientific rationale for the restrictions Texas had put into place. The answer was clearly ‘no.’ And for that reason, the Supreme Court struck down the restrictions in a surprise decision.

The cases on Trump’s transgender ban will be similar. (The ACLU has already filed, as has Outserve/Servicemembers Legal Defense Fund.) Ultimately, the question will be whether there is a plausible military or budgetary rationale for rescinding the 2016 policy. If none exists, that means the policy is discriminatory, and (most likely) unconstitutional under the Fifth Amendment’s guarantee of equal protection.

Now, it is certain that over the next six months, Mattis and his new team of experts—which he says will include political appointees—will indeed cook up some non-discriminatory rationales for excluding trans soldiers. Statistics can be manipulated, and Mattis has already said he’s “not willing to sign up” for the numbers in the RAND report. The new commission will almost certainly find some way to rationalize the ban. But as we saw in Whole Women’s Health, junk science won’t be enough.

Most importantly, Trump’s memo admitting that the deciding factor isn’t objective evidence about the costs and benefits but whether there’s a recommendation “that I find convincing” is a huge smoking gun. It is proof positive, right there in Trump’s best words, that it’s Trump’s fiat that determines this policy. That is not going to pass constitutional muster.

The military and its commander in chief have wide discretion when it comes to questions of military spending, national security, and combat readiness. Time and again, we’ve seen courts be very reluctant to second-guess what military experts have said.

But in this administration, we’ve also seen—time and again—how courts listen closely to what Donald Trump says. And when he says that a policy is based on his own opinion rather than facts; and when he makes statements that elevate himself above the rule of law; and when he persists with his views even in the face of significant evidence that he doesn’t like; and when he does so to the detriment of a vulnerable population, whether Muslim or Mexican or transgender or anyone else; courts draw the line.

That’s what courts do, in a democracy: they ensure that we live under the rule of law, not men. They ensure that demagogues pandering to the basest instincts of their base do not trump the constitution’s guarantees of equal protection. That’s why Donald Trump has lost so many times, and that’s why they are the most important guarantors of our civil society.

Trump’s transgender ban will eventually go down in flames: because once again, Donald Trump has foolishly said what he thinks, and the courts will be listening.