Closing the microwave door after heating something inside of it for too long is generally safe and will not result in trapping harmful radiation inside. Modern microwave ovens are designed with safety mechanisms to prevent the emission of microwaves when the door is closed properly.
Microwave ovens operate by generating electromagnetic waves (microwaves) that excite water molecules in the food, causing them to vibrate and generate heat, which cooks the food. These microwaves are contained within the microwave oven's metal cavity, and the oven is designed with a special mesh screen on the door to block the microwaves from escaping.
When you open the microwave door during the cooking process, the microwaves are instantly turned off through an automatic safety feature, preventing them from continuing to be emitted. Similarly, when you close the microwave door, it forms a seal that prevents microwaves from escaping while the oven is in use.
So, closing the microwave door after heating something for too long is safe and does not result in any harmful radiation being trapped inside. However, if you notice any issues with your microwave, such as the door not closing properly or damage to the door seal, it's essential to have it checked and repaired by a qualified technician to ensure it continues to function safely and efficiently.