Microsoft has added a feature to Windows XP that helps to fix errors when they arise. It is the auto-reboot feature. When Windows experiences an error, it will reboot itself in an effort to fix itself. However, there are many other factors that will create this behavior (damaged exit sound file; incorrectly configured, damaged, or incompatible hardware; conflicting programs, or an incompatible, damaged, or conflicting device drive) making it a very tricky problem to troubleshoot. Below, you will find many places on the Internet that have dedicated much time in helping you troubleshoot this issue.
Take a look at Microsoft's knowledgebase article for help:
Resources to Help Troubleshoot Shutdown Problems in Windows XP
For a complete Shutdown troubleshooting guide see:
http://www.aumha.org/a/shtdwnxp.htm
or
http://www.kellys-korner-xp.com/xp_abc.htm
then select "S" section then scroll down to the Shutdown area in the list.