I don't know that it's a comfort mechanism so much as naive dualist theories of the mind (http://plato.stanford.edu/entries/dualism/) combined with hallucinations associated with sleep paralysis (http://skepdic.com/sleepparalysis.html), instinctive seeing of faces where there are none (http://www.skepdic.com/pareidol.html), and similar phenomena.
Edit: You may well be right, of course - stories about ghosts are old, and their origins could have been in anything for all I know.
no subject
Edit: You may well be right, of course - stories about ghosts are old, and their origins could have been in anything for all I know.