No, it is not legal.
A teacher cannot cut marks just because the student’s handwriting doesn’t please him/her. That doesn’t happen on school level even.
Why the school teachers force the children to maintain their handwriting is because if the teacher who’s checking the paper doesn’t understand what’s written, then they will surely cut the marks because for them it’s frustrating to spend a lot of time on just question understanding what’s written. C’mon they have more than a hundred answer sheets to check!
Advise: Maintain a readable handwriting.