What may be happening is your computer cannot properly shut down, causing a fatal error which causes the computer to reboot.
Right click My Computer, Properties, Advanced tab, Startup and Recovery, settings. In the section for "System Failure", untick the box for "Automatically reboot", click OK, OK to exit.
Try shut down again. If there is a fatal error, it will give you the dreaded blue screen of death and stays that way, you can copy down the error message and see if it sheds any light.
A shutdown problem can have many causes. If the error message shows it's to do with a hardware driver, or some running process, you may start troubleshooting, or post the error message here for help.
The other way of finding out what's causing a fatal error is click Start, Run, type eventvwr.msc and press Enter.
Next to the system log, look for errors. Double click the item and read the error message.
For ideas on troubleshooting XP shutdown problems, click here