This is usually caused by either one of the following:
* System software getting corrupted, can be caused by a system update, not enough space on phone or for no apparent reason.
- Power management chip going faulty (This requires micro-soldering board level repair to fix)
- eMMC chip (Flash memory / a.k.a hard drive) going faulty (This requires either getting the flash memory chip replaced or reprogrammed by a JTAG (flashing box, again like board-level repair).
If you are lucky sometimes this can be fixed by reflashing the System Software (Firmware) on the phone.
Here is a link on how to reflash firmware on Samsung devices: