This probably has more to do with the fact that 30 years ago if you brought an electronic device into school it was probably relatively cheap and there was a decent chance your parents didn't even know about it. And either way it wasn't really a necessary part of your existence. Now it's a $1200 phone that is most likely the primary way your parents communicate with you between the time you're out of school (around 2:30 or 3 when I was in, unless there were after school activities) and they return from work.
I don't see how it wouldn't be legal. The school has a variety of responsibilities surrounding its students, going back hundreds of years. They aren't a 'guardian', but the school is entrusted with a child's safety, and has responsibility. For example, a school may tell a child to "be quiet" and "sit down" and "sit in this seat" and "why are you not in class", even forcing you to go to school.
The school is allowed to dole out punishments, such as detention or even denying access to the school itself. This isn't a normal "a bunch of random adults are around" relationship.
TBH, most people don't get the `in loco parentis` bit of school. It's maddening that there are comments from well-educated, smart and intelligent people in this thread who are wondering if it is legal for the school to dole out punishment to kids.
Look up the relevant legislation in your jurisdiction; dig deep enough and you will find either explicit legislation or case-law confirming that it is legal, usually with the phrase `in loco parentis`.
Any on the spot decision that needs to be made with regard to the child, the school can make it with no requirement for input or consent from the parents.
Trust me, you don't want it a different way, else one day you are going to be asking the school either a question along the lines of "Why did you wait for a parent callback before you took action?" or a question along the lines of "Why are you requiring my response to these questions every single day?"