Hello emmahardman,
It sounds like your phone needs to be restored because it goes into Recovery Mode when the battery runs out, and it sometimes turns off when there appears to be plenty of charge left. Assuming you are restoring from a backup when this happens, I would next time set it up as a new device and test to see if it happens again. If so, reset the phone with the following process and test it again:
Turn your iOS device off and on (restart) and reset
To reset, press and hold both the Sleep/Wake and Home buttons for at least 10 seconds, until you see the Apple logo.
If the issue still keeps happening, I would next seek service for the iPhone:
iPhone Repair and Service - Apple Support
Thank you for using Apple Support Communities.
All the very best,
Sterling