By the way, I glanced at the Maryland ruling, and there was a big section near the end about this very question.
Basically, Trump not only made it clear that he wanted a Muslim ban, he also made it clear how he would try to skirt the law by going about it in a shady way. And because he didn't bother with going through the proper processes first, it was obvious to the Court that national security concerns were secondary (they call them post hoc rationalizations) to the primary goal, which was a religious test:
"...But while the travel ban bars no resemblance to any response to a national security risk in recent history, it bears a clear resemblance to the precise action that President Trump described as effectuating his Muslim ban. Thus, it is more likely that the primary purpose of the travel ban was grounded in religion, and even if the Second Executive Order has a national security purpose, it is likely that its primary purpose remains the effectuation of the proposed Muslim ban. Accordingly, there is a likelihood that the travel ban violates the Establishment clause."
So, yeah, it looks like he hanged himself. Hilarious.