That's an overly simplistic (dare I say, engineering) view of how the law works. While their decisions are grounded in statute and constitutional law, as well as common law, they have broad enough latitude in how they apply it that they use a number of doctrines to actually figure out how they're going to rule even if they could rule either way based on the merits of the case. The higher up the court, the more likely this becomes - after all the case is sufficiently ambiguous that the lower courts couldn't resolve it easily. These doctrines are broadly speaking the court's view of "justness" and help them consistently apply the law to the facts of the case.
For instance, a number of laws have been struck down as being overly vague and a court could certainly find that because your hypothetical law doesn't define "shoe size" precisely enough, it's essentially void. Or if they figured that such a law was fair, they could also agree with the government that "shoe size" is commonly understood.
Put more broadly, one of the reasons the courts are so important is because they can essentially create law from thin air. For instance, did you know that the Constitution has nothing in it giving the Supreme Court the power to strike down laws? The court gave itself that power in Marbury v. Madison. (It's a bit more complicated than that, as history is, but nonetheless the Constitution doesn't mention it.) The court's mandate is deliberately left vague enough to continue to be relevant - for instance, if you piss off the court, you might find yourself jailed indefinitely for contempt, which is the only indefinite detention allowed by law. If you proscribe a court's behavior too much it becomes too easy to circumvent which leads to absurdities. Thankfully courts are reactive, not proactive, by nature - and they tend to have pretty reasonable and history-conscious people on them, so this usually works out alright.