That's not good news if you've performed a factory reset and it still occurs. Did the phone switch off, because the battery had run out of power, during the installation of a phone software update?
That happened to me once and corrupted the software causing restarts.
If it did, or didn't, I'd suggest getting the phone repaired at a Samsung store or good phone shop. They'd be able to wipe the phone clean and install the original software.