Default [Q]Phone is shutting down randomly+when taking flash pictures

The phone is shutting down randomly at times and when taking pictures with flash.connecting the phone to the charger while taking flash pictures solves the problem...note that using the flash in recording mode or in the flash light app doesn't shut down my phone. ...I tryed using a piece of paper to make sure the battery isn't moving around and I allso resetet the phone to its factory settings,I allso tryed to turn off pocket mode from sound settings since a thread sugessted that but the issue still persists. The phone says I still have 57% battery life left ....I am using the stock os.
Please help me guys