Hi Notjessie,
Thanks for reaching out in Apple Support Communities. We understand that your iPhone is restarting unexpectedly at night and this is causing an alarm you've set to not go off as expected. We can see why you'd reach out about this; we'd like to help. We'd recommend reviewing the information in this resource: If your iOS device restarts or displays the Apple logo or a spinning gear unexpectedly
Regarding the trouble you're having with the alarm, it should still sound even if your device has restarted and the screen is locked. Take some time to work through these steps as well:
If both behaviors continue, we'd suggest that you create a backup: How to back up your iPhone, iPad, and iPod touch
Then use the steps titled "Put your device in recovery mode and set it up again" in the following resource to reinstall iOS to your iPhone. These steps will erase the iOS currently installed and replace it with a fresh copy, so be sure to closely follow step four and choose to "Update" in order to prevent data loss: If you can't update or restore your iPhone, iPad, or iPod touch
Let us know what you find.
Best Regards.