“By the pricking of my thumbs,” says the Second Witch in Shakespeare’s Macbeth, “something wicked this way comes.”

Donald Trump’s thumbs have been wicked busy on Twitter. On Monday his tweets, like Banquo’s ghost, returned to haunt him again, when Judge Colleen Kollar-Kotelly of the U.S. District Court for the District of Columbia cited them as among the reasons she was temporarily blocking Trump’s ban on enlisting and retaining transgender military personnel.

It’s hard to know where this case will go in the long run; but Judge Kollar-Kotelly’s decision is a definite setback from Trump, and a significant win for the cause of transgender rights. Both the transgender ban itself, and the hateful, ham-fisted way Trump rolled it out, are self-inflicted wounds on the prestige and power of the “commander in chief” of the armed forces.

To recap: on July 26, Trump startled his own military by proclaiming in an early morning tweetstorm that:

These tweets at least purported to reverse a complex administrative review of transgender recruitment and retention that the Department of Defense had begun in August 2014. That review included a 91-page report by the National Defense Institute of the RAND Corporation, and a subsequent recommendation by a working group of senior military and defense leaders that transgender people be permitted to serve. In June 2016, then-Secretary of Defense Ash Carter set a July 1, 2017, deadline for new rules allowing transgender people to enlist and serve. In the meantime, Carter announced, “transgender Americans may serve openly” without fear of discharge.

July 1 came and went, and the new secretary of defense, Mattis, delayed implementing Carter’s order. Then came Trump’s July tweets. A few weeks after the tweets, Trump issued a memorandum to the Defense Department. The Obama Administration had “failed to identify a sufficient basis” for lifting the transgender ban, the memo said. It ordered both DoD and Homeland Security (which operates the Coast Guard) to return to the old policy and to halt payment for sex-reassignment surgery for serving transgender personnel. Defense Secretary James Mattis issued “interim guidance” protecting serving personnel from adverse action until the plan to implement Trump’s memo was completed in February 2018.

A group of serving personnel fearing discharge (under pseudonyms such as “Jane Doe 1”) and named civilians who had made concrete plans to join the military (one such plaintiff, for example, is on medical leave from the Naval Academy in order to receive gender reassignment surgery) went to court, asking for a permanent injunction against the change in policy. On Tuesday, they won an initial victory—an injunction pending a full trial on the merits.

The case involves complex questions about civilian control of the military and judicial deference to Congress and the executive. Right now, though, it’s worth looking at the way Trump’s undisciplined style and statements have swayed yet another court against his administration.

Confronted with Trump’s statements, the government sought refuge in the emerging doctrine of “Oh, That’s Just the President”; that is, it argued, the president may have tweeted or said all kinds of silly stuff—but courts shouldn’t step in until the grownups have a chance to clean up after him. Judge Kollar-Kotelly summed up the argument thus:

the Presidential Memorandum merely commissioned an additional policy review; that review is underway; nothing is set in stone, and what policy may come about is unknown; and regardless, Plaintiffs are protected by the Interim Guidance.

Kollar-Kotelly dismissed this as a “red herring”; she felt constrained to remind the government that the “President controls the United States military … To the extent there is ambiguity about the meaning of the Presidential Memorandum, the best guidance is the President’s own statements regarding his intentions.” Thus, absent an unforeseen turnabout by Trump, the current service members will be discharged next year, often with loss of pension rights and family medical benefits, and the would-be service members will lose their chance for a military career.

She found it significant that the original decision to lift the transgender ban involved several high-level reviews and a RAND study—while the decision to reverse it, as near as the record shows, involved Donald Trump waking up with itchy thumbs. The 2016 policy change, promising the freedom to serve openly, induced transgender service members to come out to their commanders and comrades. Then, Kollar-Kotelly wrote:

The President abruptly announced, via Twitter—without any of the formality or deliberative processes that generally accompany the development and announcement of major policy changes that will gravely affect the lives of many Americans—that all transgender individuals would be precluded from participating in the military in any capacity. These circumstances provide additional support for Plaintiffs’ claim that the decision to exclude transgender individuals was not driven by genuine concerns regarding military efficacy.

In fact, she added, “all of the reasons proffered by the president for excluding transgender individuals from the military in this case were not merely unsupported, but were actually contradicted by the studies, conclusions, and judgments of the military itself” and “had been studied and rejected by the military itself.”

From these facts, the judge concluded that Trump was likely acting purely out of hostility, or “animus,” toward trans people; and though as commander in chief his powers receive deference from the courts, “the Court is not powerless to assess whether the constitutional rights of America’s service members have been violated.” Previous cases have examined, for example, whether the military was discriminating against its personnel on the basis of sex or religion. Whatever leeway Congress may have in setting qualifications for service, the Constitution can’t possibly allow the president unilaterally—without legislation, consultation, or review—to purge the service of a group he just happens to dislike.

“The Court by no means suggests that it was not within the president’s authority to order that additional studies be undertaken and that this policy be reevaluated,” Kollar-Kotelly wrote. “If the President had done so and then decided that banning all transgender individuals from serving in the military was beneficial to the various military objectives cited, this would be a different case.”

Those words may eventually be seen as the epitaph for the Trump presidency. A president who learns to govern can achieve a great deal; but learning to govern is beneath Trump. He tweets and skates, leaving the courts to repair the damage.

The ponderous ways of bureaucracy are not obstacles, but important aids, to effective government. Study, interagency review, and legal review make it more likely that officials won’t make impulsive, overbroad, and counter-productive decisions. Time and again—in the grotesquely botched “travel ban” orders, in the overreaching “sanctuary cities” order, and now in the transgender ban—Trump has ignored the functions and interests of the government he heads, opting instead for a quick jerk of the thumbs.