Many schools enforce things such as uniform for the journey to and from and seem to the think that is legal, this isn't very different to that. There is usually some kind of home/school agreement which students and parents are required to sign up to which would cover this kind of rule.
I suspect that this wouldn't be enforceable in any way. If your child is not in the care of the school at any moment, I very much doubt that they can dictate what they wear.
If a school implements a policy like this it's very hard for a single student/parent to fight against it. Maybe it isn't legal but taking the school to court will cost silly money and take years, meanwhile the kid has a problem day to day.
Many schools enforce things such as uniform for the journey to and from and seem to the think that is legal, this isn't very different to that. There is usually some kind of home/school agreement which students and parents are required to sign up to which would cover this kind of rule.