In my view, what happened to you was wrong and regrettable, but it was not illegal for the teacher to do what she did.
There are no laws against that teacher’s behavior because it is very hard to write laws or rules that would exactly define what sorts of comments are and are not rude. Imagine, for example, that you had to write rules about how teachers could behave towards students. How would you write them in such a way as to cover every situation imaginable?
For better or for worse, teachers are supposed to help teach students how to behave in various life situations. This is particularly true in middle school (you do not mention what grade you are in) but it applies in high school to some degree as well. They are supposed to help students understand when their behavior is rude. This means that it is part of the teacher’s job to correct you if they think you are acting improperly.
Of course, when the teacher is doing that, she is supposed to be modeling good behavior herself. Teachers are taught to try not to escalate situations and to try not to get in students’ faces (see the link below). Assuming that this incident happened just the way you say it did, this teacher acted in an unprofessional way.
The only thing I can say in the teacher’s defense is that teachers often end up having to spend much of their day correcting student behaviors that really are bad. They get worn down and frustrated and can be easily irritated. This is not an excuse, it is just an explanation. Teachers, almost without exception, really do try to get it right all the time. However, it is hard to do.
The experience that you had sounds very unpleasant. It is sad that it happened and I would hope that the teacher realizes that she made a mistake. Sadly, teachers are easily capable of making mistakes. What she did was unprofessional, but it was not illegal because it would be hard to write rules that would cover all situations.