Praise be to Allah.
If these students have been informed about the things which they are not allowed to use in class or bring to school and have been told that whoever breaks the rule will have it confiscated from him, it is permissible to punish those who break the rules by confiscating them. If they are items of little value, such as pumpkin seeds, it is permissible to dispose of them, but if they are valuable items they should be returned to the student or his guardian at the end of the day or at the end of the school year, according to whatever the school thinks is best.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) was asked: Is it permissible for the teacher to take things from some students which may be valuable, with which they were playing in class during the lesson, and give them to the school?
He replied: That is based on the issue of whether it is permissible to punish by taking wealth or property. Some of the scholars say that it is not permissible to punish by taking wealth or property in any case except what is mentioned in the texts. Some of them say that punishing by taking wealth or property is permissible and this is the more correct view. But if the students have something that they are playing with and he has warned them, for example by writing on the blackboard or posting a notice, that if anyone brings something and plays with it, it will be confiscated, then in that case he may confiscate it, but if it is something valuable and the student is poor - for example -- then it should be kept safely at the school, and at the end of the year it should be given to the student or his guardian.
End quote from al-Liqa’ al-Shahri, 48/15
And Allah knows best.