It is not necessarily illegal for a teacher to collect a student's mobile phone. If the teacher confiscates the mobile phone and directly hands it to the student's parents, or if the teacher confiscates the mobile phone and guarantees to return it within a certain period of time, it is not illegal.
However, if the return time limit is too long, or the owner insists on disagreeing, but the teacher still owns the mobile phone, it may constitute an infringement of the owner's right to possession and disposal, which is illegal.
[Legal basis] According to Article 240 of the Civil Code, the owner has the right to possess, use, benefit from and dispose of his real estate or movable property according to law.