Had this very same problem with an iPhone X immediately following a housing swap. I contacted STS Telecom (Which I totally recommend for data recovery) and the technician informed me that the iPhone X will restart by itself every 3 minutes if the charging port is not connected or it is broken. I went on eBay and ordered a high-quality replacement cable ($10-$15) and viola it was working good as new! I know this may not be the exact problem, but I hope this helps!
P.S From what I have heard, there is a temperature sensor on the cable and if the cable does not have that or it is damaged it will cause the phone to have a kernel panic and thus shutting the phone down. so make sure you have a good quality cable!