Do you want the science version or the mystic one? ...
science : short version , your brain don't know the difference or awake or sleep you still capture stimulus from your enviroment even in your sleep, and process them just them same, when your consciousness mind (sorry english second language) shuts off your memories and thoughs are good as the real thing, that's why dreams (nightmares) are so real and still linger even after you are awake. there is different levels of nightmares (don't know the name for the real bad ones in english) but I use to have them all the time (sometimes still do) and it takes a long time to get me awake good enough for me to reconise where I'm etc...(plus I walk on my sleep too LOL )
mystic: some people believe you more open to comunicate to the other world and spirits when you are sleep (same a medium trance) , some people can comunicate better then other (it's believe children do it all the time hence imaginary friend) , and/or your dreams (the ones that make no sense) are memories from other life , that why you see people in your dreams you know but you don't really know where from , places etc...
did it help? if not let me go grab my chicken bones and I will be right back