the thing is, sleep and wake is controlled by a part of the brain, and REM and non-REM another separate part. These don't always synchronise correctly, especially when sleep deprived.
REM sleep, Rapid Eye Movement is when we replay memories from short-term memory to long term for storage. As we awaken from these dreams we can guide them. When in REM we paralyse the body, so we don't act out our dreams.
Sometimes things happen out of order, you can re-gain your muscle control, and still be asleep hence sleep talking/walking etc. OR
You can consciously awaken, but still be dreaming aka Hypnogogic Hallucinations but still be paralysed. Technically your still in REM. Things you see/hear are because your hallucinating (dreaming). And trust me, your brain will take things and run with it.
These things are brought out more when sleep deprived. Very important to look after our sleep and not abuse it.