I once thought of Smashes Idea, however, I had a different theory.
When we die, our minds are set on, what happens next. Then, your brain subconsciously places you in a scenario what you think is after death. For example. If you think you get reincarnated after death, your brain will place you in a dream where you are reincarnated. But I gave up on that long ago.