President Donald Trump is zero for two in his attempts to implement a Muslim ban, and the cause of his continuing failure is President Donald Trump. I’d call that ironic, if irony were still a thing.

It’s being widely said that Trump is basically out of control, and seemingly uncontrollable. His administration veers wildly across eight lanes of traffic, minute to minute, as his aides try to manage the conflicting messages he blurts out, and all arms of government are working hard to maintain some semblance of normal governance and due process. 

Meanwhile, the Commander in Chief tweets on with pathological disregard for decency or consequence. The concern is, since he won’t control himself, what can? He is, after all, in charge.

It would be foolish to predict the ending, but the battle for the soul of American democracy is increasingly fascinating. As I so sagely predicted a while back, the courts are in the vanguard of the fight; interestingly, their primary weapon is turning out to be Trump himself.

Court judgments can be quite entertaining, and Trump’s second attempt at the Muslim ban has produced a couple of crackers. US District Judges Derrick J Watson in Hawaii and Theodore D Chuang in Maryland did not hold back in their twin impositions of injunctions preventing key aspects of Trump’s executive order from taking effect, smacking the President around the head with his own carelessly crafted words.

Trump’s first effort, in January, sought to place a total freeze on entry into the US on all nationals of seven nations: Iran, Iraq, Syria, Yemen, Sudan, Somalia and Libya. It also suspended all refugee entries for 120 days. Critically, it ordered that priority be given to refugee claims from people whose religion is in the minority in their home country.

The District Court, and the Ninth Circuit on appeal, put a stop to that executive order, on the basis that it was a disguised attempt to implement a religiously discriminatory immigration policy, most likely unconstitutional and outside the president’s powers. Naturally, Trump responded by seeking to undermine the independence and legitimacy of the courts rather than seriously addressing the legal concerns they’d raised. When it came down to it, however, he wilted and didn’t appeal to the Supreme Court.

Instead, he had another crack at getting the wording right. The White House spin was that the courts had raised only some “technical issues”, which could be easily ironed out. In saying that, Trump’s senior adviser and in-house fascist Stephen Miller also explained that the revised version would be fundamentally the same as the original one, noting for posterity that “the powers of the President to protect our country … will not be questioned”.

Yeah, good plan. So far as the courts are concerned, a Muslim ban by any other name would still smell so rancid. Executive order No. 2 is as dead in the water as the first one.

The central issue is the “establishment clause” of the US constitution, which was designed to ensure that church and state are kept forever separated. Most relevantly, the government is prohibited from seeking to establish anything like a state religion, which includes doing the reverse: acting to disfavour any religion.

A law will fall foul of the establishment clause if it does not have a “primary secular purpose”. The executive orders, both judges found, have the purpose of discriminating against those who follow the Muslim religion. The fact that the second version doesn’t mention religion at all (the reference to giving priority to religious minorities has been deleted) and is ostensibly targeted at nationality without reference to religion, was seen by the courts as a paper-thin facade for the real underlying purpose. The fact that all six named countries (Iraq was left out this time) are more than 90% Muslim (some 99%) was taken as a compelling indicator of what’s really going on here.

Both judges referred to a classic piece of Trump performance art as evidence of his true purpose. When he signed the first executive order in January in front of the cameras, Trump said “This is the ‘Protection of the Nation from Foreign Terrorist Entry into the United States.’” He then looked up, meaningfully, and added, “We all know what that means.”

The courts had plenty else to go on, and they recited numerous examples of Trump, particularly during his campaign, explicitly calling for a “total and complete shutdown of Muslims entering the United States”, saying “Islam hates us” and referring to “this propaganda spread all through the country that [Islam] is a religion of peace”.

Perhaps the kill shot was delivered by Trump’s henchman Rudolph Giuliani, who went on Fox News the day after the first Executive Order and said “When [Trump] first announced it, he said ‘Muslim ban’. He called me up.  He said, ‘Put a commission together. Show me the right way to do it.’”

The judges found it a simple matter to connect the dots from Trump’s substantial public record of demonising Muslims and explicitly calling for their banning, to both attempts at drafting an order, which is directed towards exactly that purpose but is designed to look like something else. 

The true beauty of this situation is not just that the judges have hung Trump with his own words, but that it’s his well-worn schtick of nodding and winking to his fan base of bigots — letting on in not so many words that “we know what’s really going on here” — which enabled the courts to say “yes, so do we”.

This, of course, is how the rule of law and responsible government are supposed to function. The instruments of governance — judiciary, legislature, executive — are held accountable by each other for their words and actions.  The courts have just given an object lesson.  Elements of the executive, such as the FBI, and parts of Congress, are trying to do much the same thing, taking what the President and his minions say and applying the ordinary rules of engagement to them.

The purpose of this play is not just to embarrass Trump and hoist him on his own stupidity; it’s an attempt to save the institutions that he is assiduously wrecking. So long as he and his team play the game within its traditional outer boundaries — by ultimately respecting the umpires’ decisions and not, for example, arresting all the judges — then democracy can survive his depredations.

However, given Trump’s own total disregard for all norms of civil conduct, and the dark presence of lunatics like Miller and Steve Bannon in his ear, it’s fair to wonder whether the gloves are going to remain on. I don’t think they will. More likely, the President is right now asking himself, what would Putin do?