Whether the computer does a shutdown, or keeps running, depends on how the BIOS interprets the signal. You can change the options in the BIOS.
When the computer does not shut down right often it is a sign that you have a bad power supply. Even electrical stuff wears out.
The motherboard tells the power supply what to do via some kind of low voltage signal. So if the power supply is not 100% working within design specifications or the power even fluctuates just a little say by 1-2 watts out of spec, then it will not work properly. The power supply may function well enough to power the computer but not to shutdown or start up properly.
The mechanical power button may also not be working or sticking a little bit. Even the case being out of alignment with the button can cause problems. Often a plunger is being depressed to make contact with the button, than pressing the button itself.
The House power supply can be at issue also. Computers require a grounded power supply to work properly. Sometimes this may require installing a better grounded plug or running a grounding wire to a copper grounding stake or metal pipe that goes into the ground. The power company can also cause problems. Sometime in some areas there are brown outs and the power fluctuates. I have seen this in the summer time when an electric fan would speed up and slow down or a tape deck would mash up the tape because it is slowing down and speeding up. Sometimes using a UPS can help to stabilize the power levels.
However, often it is just a power supply that is starting to fluctuate. A power supply also has cooling fins on certain parts and they can become clogged up with dust. If it overheats, damage can be caused to the power supply. Once damage is done it is too late to clean the dust off. Not all power supplies are created equal. Some are heavy duty and they dont heat up much when used, and they are safer. The cheaper ones that heat up more tend to be easier to burn out. So ideally you want a power supply that can handle the load without heating up. Power supplies are rated and usually they have a technical page that shows how they handle a load that shows a power curve. This is why you want a power supply designed to run in the sweet spot of the power curve under load. When a power supply works at the high end of its load it runs less efficiently and runs hotter. More heat equals wasted power.