When a PC acts the way you are describing, it is basically trying to "protect" its self.
There are a few things that can cause a PC to shut down on it's own, and then try to start on it's own.
One reason can be that it is so filled with dust inside, like all over the heat sinks, RAM, video card, power supply and vents blocked, that it overheats, and the BIOS is telling your operating system to shut down.
Another reason can be a faulty power supply, or the power supply is not securely plugged into the motherboard. There will be just enough voltage to kick on the PC but not enough to run all the components, so it shuts down to protect its self.
When I worked in an IT dept in a big casino once, we would have computers shutting down by them selves. We would take them outside and open them up and find them completely filled with dust and dirt. Many times, if they haven't fried themselves yet, or popped some caps, we would clean them out real good with compressed air, plug them back in, and boom, they would run perfect.
Many clients I have had don't seem to understand how important it is to keep the guts of a PC clean. Air flow is vital for the health of a computer, and keeping the heat down, by keeping it clean is primary.
Sometimes it will be a bad virus, or hijacking software or malware. Usually a good anti virus program can deal with that.
Also, swelled or burst caps can cause this problem, but taking it to a good trusted troubleshooting tech might be in order for this issue.