This is an obvious misuse of authority. The punishment is far far more severe than the crime. If the school administrators are unwilling to use judgment and discretion in their enforcement of the rules then they don't deserve my support as a parent. If you are going to give my kid detention for bringing a Jolly Rancher to school or receiving one from a friend you should expect me as a parent to sick and army of lawyers on the school district and not let up until the case gets to the Supreme Court. Why? Because the law you are enforcing is stupid if it doesn't allow you the discretion to inflict a punishment that fits the situation.
And, for sure, if you were willing to take the issue that far, it could be productive. You could get the stupid rule changed - which is often (and, specifically, in this case) beyond the power of the teacher or principal, and a much more worthwhile end than simply negating the immediate consequences of one violation of the rule.
Specifically what I do not approve of is people responding to things like this by going to the teacher or principal and verbally abusing them, threatening them, etc. First off, it's just flat-out rude to do so. Second, it undermines their authority, giving your child the sense that any time the teacher does something they don't like, they can just come running to you to overrule the teacher's authority. That, to me, is absolutely the wrong lesson. It's not always right to yield to unjust rules, but most of the time rebelling against authority isn't the right decision either. What happens when you get a speeding ticket? Do you yell at the police officer, threaten him with lawsuits, etc.? Most people would say that's a bad idea because of the possibility that this will just get you in more trouble. Beyond that I contend that this is simply wrong. Contradict the officer if he is wrong, but show respect, because he has a position that commands respect. If you want to fight the charge, there's a process to follow, and yelling at the guy who enforces the rule is not part of it.
In one sense, that's a pretty ugly idea - resigning oneself to the fact that there are powers in the world to which one must submit. But that's a reality in this world. Authorities exist, and rebellion against them is something you reserve for desperate situations.