There are several possible reasons why your phone is shutting down every night. Here are some steps you can try to troubleshoot the issue:
Check if there are any apps that might be causing the issue.
Check the battery usage details to see if any particular app is consuming a lot of battery. To do this, go to your phone's settings and select "Battery" or "Power". From there, you should be able to see a list of apps and how much battery each one is consuming. If you find any app consuming an unusually high amount of battery, try uninstalling it or restricting its background activity.
Check if there are any software updates available for your phone. Sometimes, bugs can cause issues like this, and updates may contain fixes for these bugs.
Check if your phone's battery is in good condition. Over time, batteries can degrade, which can cause them to shut down unexpectedly. You can check your battery health by using a battery monitoring app or by taking your phone to a professional.
Consider performing a factory reset on your phone. This will erase all data on your phone, so make sure to back up any important data before doing so. To reset your phone, go to your phone's settings, then select "Backup and reset". From there, select "Factory data reset" and follow the prompts to reset your phone.
If none of the above solutions work, you may want to consider taking your phone to a professional for further diagnosis and repair.