Here’s an article from the New York Times on the dreams that people have about death. This is a common phenomenon in the final weeks of life. It probably happens more than we think; not everyone shares such things, no doubt because it is very difficult to predict how people will react. Family members get dreams like this, too. I think we know, intuitively, when our loved ones are ready to leave us, in much the same way we know intuitively when they are not feeling well.
I think the best explanation is that these dreams arise in the subconscious; it’s a way for the subconscious mind to communicate with the conscious mind. But keep in mind my Jungian tendencies; I see evidence that there is a great deal of information available in the subconscious mind that speaks to what it means to be human. There is evidence that there are parts of the Self that transcend spatial and temporal boundaries; these parts are located where dreams come from. I rather suspect we are all connected to “The River” way down deep. This is an important article, and speaks to a part of the mind from which we all to often cut ourselves off.