Question: how to fix your iphone 7 when it keeps turning off?
Answer: Force restart your iphone 7: Press and hold both Power (side) and Volume Down buttons for at least 10 seconds, until you see the Apple logo. When it appears, release both buttons, wait for your iP7 to restart, then test it for a while. If this doesn't help you, I would try to install a fresh copy of iOS.