Welcome to iPhone Forums!
Your iPhone might refuse charging when locked because of a setting. So take a look at the following:
Go to the Settings app, scroll to Touch ID & Passcode. Enter your passcode, then go to USB Accessories and make sure it’s enabled.
Your iPhone could be in a restart loop for various reasons. Here’s what you can try to fix this:
- Remove the SIM card. If the iDevice stops rebooting, pit the SIM card back in. If the problem starts again, contact your carrier, or restore your iPhone.
- Force restart your device: press and hold Home and Power button until you see the Apple logo. As soon as it appears, let go of both buttons.
- Use iTunes to restore your iPhone:
Restore your iOS or iPadOS device in iTunes on PC
Make sure there’s a most recent backup. If that doesn’t help:
- Put your iPhone into DFU mode and restore it:
How To Put An iPhone In DFU Mode, The Apple Way
- Take a look at the charging port. If there’s any debris, remove it cautiously.
If your iPhone keeps restarting in spite of this, a repair might be necessary. Contact Apple, or visit the next Apple Retail Store.
Hope that helps.