Most jobs have a dress code. Why do people get up in arms about schools having a dress code? Granted, I think it should basically come down to what is appropriate or not vs. specific rules if there is not a uniform. But, unfortunately, it seems there always seems to be those that either don't grasp what is appropriate or don't care so we end up getting specific rules. (Not directed at the OP or anyone specific-to society in general.) As to why the rules seem sexist-I think we need to take that up with clothing designers. I rarely see boy's clothing that is specifically designed to emphasis their body. Where as so much of female clothing does-even some of the clothing for young girls. But yes, if boys are wearing inappropriate clothes, then they need to be called out too. It's just that the majority of boy clothing styles, that I have seen, aren't inappropriate for school. (The sagging pants trend would be the exception. Is that still around? That was around when I was in high school 20 years ago!)
I do think that if the teacher can't tell that the shorts are too short (aka inappropriate) just by a passing glance at them-then they are probably fine and the calling students out in the middle of class to formally check is unnecessary.