You are raising an important point, but the simple answer is: in this country we have a system of checks and balances to ensure that our elected leadership does not make decisions that are binding an unilateral.
The media gets this wrong almost every time. It is not the judge issuing a ruling out of thin air. Chicago Mayor Brandon Johnson challenged Trump's interpretation of the law in our court system, asking for a temporary injunction (a ruling that would prevent Trump from deploying the National Guard) and received it. The reasoning, which is quoted in the article as if it came out of thin air, is the judge's logic explaining why she ruled in Johnson's favor, granting the injunction.
Trump has the right of appeal, which he will exercise. Based on previous rulings, the case is likely to be escalated to the Supreme Court (on its emergency or what is sometimes called "shadow docket") where the justices will answer the question, "Was the ruling correct in light of the statute (or law)."
We have ample precedent that tells us the injunction will probably be overturned. More than half of the Supreme Court Justices following a model of jurisprudence called "constitutionalism" (sometimes "originalism") that interprets laws in light of what they mean when they were written. More liberal justices rule as if the Constitution were a "living document," and therefore it is shaped by current political culture and climate. They are in the minority, however (Kagan, Sotomayor, and Jackson-Brown). So the ruling is probably going to be 6-3 in Trump's favor. Robert's, who is Chief Justice of the Court is usually a swing vote and he will join the majority in major decisions to give the ruling legitimacy.
When the injunction is overturned--again, the question here isn't "Is Chicago a war zone that makes it necessary for Trump to dispatch the National Guard?" It's "Does Trump have the authority to do it?" (Well, the Constitution does give him the authority, so...) you should expect another round of MSM outlets (with the exception of Fox News) claiming that "the Supreme Court has sided with Trump" because they have, while completely ignoring the reason they did so: the Constitution permits Trump to do so. This implies that the Justices are pro-Trump, which could not be further from the truth.
The Supreme Court is not ruling on the appropriateness of Trump's decision. Johnson will not be able to appeal the injunction, but he will be able to file another case in the future that questions Trump's decision on grounds other than his authority to make it.