Because children are taking them out in class. If a child actually keeps the phone in their bag that's fine, but if they take it out (and it's not a true emergency), the teacher has every right to confiscate it.
And I would argue that they don’t have the right just as your employer doesn’t have the right to take your phone. Apparently a lot of parents agree with me which is what spawned this comment chain.