If you hear noises from the motor, they usually come from the bearings, more rarely from the thru axle (Clicking, ST1x). Loose rotor magnets in electric motors are also rare, but do occur.

The magnets are glued. The adhesive must be able to withstand both mechanical and thermal stresses. The latter means temperatures of up to 150 °C. To reduce the drying time, manufacturers usually use cyanoacrylate adhesives (instant adhesives). However, these are not really heat-resistant and, as they are hygroscopic, are not immune to moisture.

DIY repair
In the unlikely event that this should occur, a heat-resistant 2-component epoxy adhesive can be used. First sand everything clean, clean with IPA (isopropyl alcohol), apply and spread adhesive, insert magnets, remove excess adhesive and allow to harden at room temperature.
Further information
> See also PROBLEMS - MOTOR - 'Repairs to the TDCM hub motor'
> speedpedelecreview.com | JanR
> YouTube | EBike Builder
> YouTube | Grin Technologies
etc.