If your iPhone battery is damaged, it may cause it to reboot while charging. In this case, you can try replacing the battery with a new one.
If you are using a charger that is not original or is damaged, it may also cause your iPhone to restart repeatedly while charging. And you can try replacing the charger, preferably with the original one.
If there is an issue with the apps your iPhone is running or with the iOS system, your iPhone may iPhone reboot during charging. Try updating your iOS or restoring your iPhone to factory settings.