germany
In Germany, the exact rules depend on the Land (state), as education is regulated by them. However, the rules mostly seem to boil down to: "Confiscation is allowed to enforce discipline, but things must be returned as soon as practical."
For example, In North Rhine-Westphalia the relevant law says:
(2) Zu den erzieherischen Einwirkungen gehören insbesondere [...] die
zeitweise Wegnahme von Gegenständen [...]
Schulgesetz NRW, §53
Translation (mine, no guarantee):
(2) Among the disciplinary measures there are [...] the temporary
confiscation of objects [...]
So confiscation of objects by teachers is explicitly authorized, however the confiscation must be "temporary". The law does not say what exactly "temporary" means, but it does say that measures must in general be "proportionate".
There is some clarification on the web site of the ministry of education:
Darf eine Lehrkraft einer Schülerin oder einem Schüler das Handy
wegnehmen?
Auch die Wegnahme von Gegenständen ist als erzieherische Maßnahme
ausdrücklich zulässig, wenn sie zur Aufrechterhaltung eines
ordnungsgemäßen Schulbetriebs erforderlich ist (§ 53 Abs. 2 SchulG).
Eine prophylaktische Wegnahme von Gegenständen ist nicht zulässig. Die
Störung muss entweder bereits eingetreten sein oder unmittelbar
bevorstehen und auf andere Weise nicht zu beseitigen sein (Grundsatz
der Verhältnismäßigkeit).
Schulrecht - Ordnungsmaßnahmen; Erzieherische Maßnahmen
Translation:
Is a teacher allowed to confiscate a pupil's mobile phone?
The confiscation of objects is explicitly permitted, if it is
necessary to maintain school discipline (§ 53 Abs. 2 SchulG). A
preventive confiscation is not permitted. The disturbance [of
discipline] must already have happened or be imminent, and must not be
avoidable in a different way (principle of proportionality).
So while a teacher may confiscate objects, they must be returned as soon as the disruption of discipline has been resolved, which presumably means at the end of the school day at the latest.
Note that confiscation is explicitly not mentioned as a punishment, so this is not permissible. If, for example, a student repeatedly brings along an object that disrupts the lessons, then the school may not confiscate the items for a longer time or permanently. Instead, it must take other measures (also detailed in the law), such as temporary exclusion from school, or even expulsion.