This is a boundary problem. Tell your kid that everyone always keeps their private parts hidden in public places (which includes school), unless you have a potty accident and then it’s okay to get the teacher to help you clean up.
Do not spin it as adults being “weird” because that’s false and you shouldn’t lie to your kids. It’s normal to keep nudity completely to oneself in one’s bedroom and bathroom when one is under 18, and to oneself and one’s sexual partners behind closed doors when one is over 18, unless one lives in a nudist colony.
For everyone saying they don’t think this is worth getting concerned over, would you be okay with this if your kid was at another kid’s house and this happened? Or if it happened in your house? What if the kids were 12? It’s just not acceptable, and better to nip in the bud before this becomes a habit. I would not be happy if my kid was doing this with another kid, even outside the school context.
If you want to satisfy your kid’s curiosity about what the other sex has inside their pants, grab a medical textbook. While I agree that you don’t want to instill a sense of body shame into a kid so young, you also don’t want to raise a kid who pushes what can be viewed potentially as sexual bounds at this young of an age. Whether you like it or not, this is what other parents will think, if it becomes a habit. Unless you raise your kids in a nudist colony.
I have a potentially relevant anecdote. When my little cousin (who just turned 10) was a toddler, she used to reach into her pants and rub her underwear between her fingers as a self-soothing technique when she was sleepy, and she would do this in public. She wasn’t masturbating but it seriously looked like she was. When family members brought it to my uncle’s attention, and that it looked creepy and wrong, he said “It’s no big deal, she just likes the feel of the fabric.” I don’t know why he wouldn’t get her a blankie made of underpants material or something, but he didn’t and he didn’t bother teaching her that what she was doing wasn’t acceptable in a public place because it looked creepy and wrong. She was still doing this at age 8, and when she hosted a slumber party she got singled out and embarrassed for it by her friends. Peer ridicule finally got her to stop. But her father should have taught her that. Would have spared her a lot of shame.
Norms can be pointless, yes, but unless you want your kid to be viewed as abnormal then you should adhere to them. I say this as someone who adheres to very few norms in adulthood. But I’m glad I was raised taking (most of) them for granted as a kid, because otherwise my childhood would have been very unpleasant. It’s the same reason you don’t name a kid Apple Skyfeather Hippiekid Smith. Why start them out with a disadvantage that’s going to get them singled out negatively?