Apple has issued guidelines regarding the optimal use of their devices to ensure user safety, and keeping the phone away while sleeping is one of the points noted.
This is primarily due to overheating risks and charging safety:
Overheating risks: Sleeping with a phone, especially under a pillow or blanket, can increase the risk of the device overheating. This not only poses a potential safety hazard but can also affect battery performance and longevity.
Charging safety: Charging a phone in bed or under a pillow can pose a fire risk if the device or charger overheats. It's safer to charge the device away from the bed and on a non-flammable surface.
Apple's warning is part of broader advice from health and safety organisations that recommend minimising close, prolonged contact with mobile devices during use and especially while sleeping, to ensure both safety and a healthier sleep environment.