The human mind usually is able to achieve a sense of balance between reality and delusion. When we dream, we have temporarily lost that balance. When we awake we find it again.
Scientists say the sense of self, the balance between knowing your own body exists and the thoughts about that body, requires several parts of the brain to work together. When they don’t, we see the strangest behaviors.
One man tried to commit suicide but was unsuccessful. A few days later he began to believe he was dead–told several people. When they argued with him, he said, “My mind is OK. My brain is dead.” This mental illness has a name and the man eventually recovered.
Another man thought his leg belonged to someone else. He tried to cut it off. Something similar happens when a limb is cut off the person feels pain as if the limb is still there.
Visions of the Virgin Mary, Jesus and Elvis are an entirely different mental phenomenon, but they illustrate the power the brain has to be off balance between what is actually happening and delusion. Ancient story telling is heavy with visions which probably seemed as real to the person as reality seems to me at this moment.
These creative works by the brain are the stock and trade of religion. Whether it is the Paul of the Bible having frequent conversations with a dead Jesus or Joseph Smith hearing a voice telling him start the Mormon church, the brain can invent a new religion.
[An article discussion the brain and sense of self is linked in comments.]