Generally when you're logging out of your account in OS X the system will ask for confirmation, and will wait for you to close unsaved documents before it closes your log-in session; however, on rare occasions your system may suddenly log out without you telling it to. At one moment you will be working, and the next moment the system will suddenly show either the log-in screen or the open Finder only.
MacFixIt reader "53pickup" wrote in with this exact experience:
Recently (over the past 6 months) on my MacBook Pro (2008) I have come back to my computer and found that all the apps that I had left open were closed, including unsaved files in Illustrator, etc. I was perplexed, until yesterday when I witnessed the action taking place. Without any warning the screen turned blue for a few seconds and when the Finder came back up, all the apps were closed.
When you start up OS X, the system kernel (low-level hardware management software) starts up an umbrella launcher process called "launchd," which during the boot sequence will start up a number of background processes under the root account (the main system account) and then will present the log-in window. When you provide user account credentials, the system launcher will start up another mini launcher instance under the new username, so programs and processes that your account launches will be contained under their own umbrella process. This setup allows the system to better sequester programs that individual accounts will be running, so if one user runs a buggy program it will at most affect only that user's log-in session, and not the log-in sessions of other users or the system as a whole.
While this setup is beneficial in this regard, it can cause some unwanted behavior if some processes that the log-in session depend on become unstable and unexpectedly quit. These include the window server, the log-in window itself, and the user's "mini umbrella" launcher (launchd). If this happens then the whole log-in session (the mini umbrella for the user account) will shut down, closing all programs the user is running, and dropping the user to the log-in screen (or automatically logging back in if the system has automatic log-on enabled).
Naturally if this happens (and especially if it happens regularly) then you might be concerned, but there are a few things you can do to tackle the problem if it happens more than once:
Run general maintenance.
Performing a general maintenance routine will clear system caches and temporary items that, if corrupted, may be contributing to the faulty behavior.
Uninstall third-party add-on programs.
If you have recently installed any drivers, fonts, other system add-ons, or background applications on your system then uninstall them to see if the problem persists after they are disabled or removed.
Troubleshoot peripheral devices.
If you have any peripheral devices attached to your computer, remove them. Sometimes peripheral devices can malfunction and cause odd system behavior. Run the system for a while with them unplugged and then reattach them one by one (running the system for a while incrementally) to see if one of the devices is contributing to the problem.
Reapply the latest Combo updater.
If you are experiencing odd system behavior, one common step in addition to running a general maintenance routine is to reapply the latest combo updater for OS X. Download the most recent combo updater for your system (such as Leopard or Snow Leopard) from the Apple Support Downloads site and run it when booted into Safe Mode (to enter Safe Mode, hold the Shift key at start-up).
Reinstall OS X.
As a last resort, you can try reinstalling OS X, which should help fix this problem if nothing else does. Reinstalling the underlying OS is relatively easy with Snow Leopard through the standard installation procedure, and can be done in Leopard through an Archive and Install procedure. Once this is done, be sure to update your system and then test it out again to see if the unexpected log-outs continue to happen.