If your iPhone is shutting off every time you put in your Apple ID, it may be due to the battery being degraded. It could also be that your device is crashing every time you try to put in the code, which might be something to contact Apple Support about.
Hope your issue gets solved!