Ref: NDEs and lucid dreaming etc.
We still don't really understand the whole concept of consciousness, we think we exist in this world but all we know is what our brain knows, and all that knows is electrical signals from our sensors (imagine losing your sense of smell, then taste, then hearing and sight, all you could do is touch - lose that and what can you know?). Just like the Matrix you could fake those signals to a brain and tell it whatever you want it to believe.
So then, what is consciousness? What makes us understand those inputs and put them all together to form this 'reality'? Whatever that process is it controls our entire life - including dreaming, and also people with mental problems, hallucinations etc. It's a small step to think that when you 'die' that consciousness process takes over again and fills your 'reality' with images that just so happen to agree with your own beliefs.