Common reasons why your iPhone keeps randomly turning off

Wait 5 sec.

If your iPhone's battery can't keep up with what you're doing or you overwhelm its hardware, it might shut down to protect itself.