We are apes. We came from an ape-like ancestor roughly ten to fifteen lakh years ago. We have made our way on this planet by using a few qualities that evolution bestowed upon us. One of these qualities is imagination. Yuval Noah Harari (author of Sapiens) calls the acquisition of this gift the Cognitive Revolution.
From human imaginations came structures that hold society together. These structures were not physical ones, but they did end up being the foundation for a lot of physical things in our lives — places of religious value, sacred artifacts, clothes that mark some members of society as being different from others (priests and monks), ideas like good & evil, morality, and even justice.
I have personally come to the conclusion that the idea of justice, more than anything else, is the reason behind the idea of an afterlife.
Think about it. What is justice? It is the assumption that human beings are responsible for the consequences of their actions. Nations have legal frameworks that ensure justice is meted out. Holy books of many religions speak of what constitutes good deeds and bad deeds. They even contain elaborate descriptions of the consequences that people will suffer for their deeds. Some of these consequences come to us while we are still alive — prison, a thousand lashes, stoning, banishment etc. Other consequences — punishments and rewards so great that nothing in this world can possibly measure up — are said to belong in the life after death.
Religions are stories that we made up to make sense of our place in the world. These stories grew in size and scope and listeners became followers and then actual characters in the stories. The rules of the stories began to apply to the people who were listening to them. It is not something that is often readily apparent, but the stories you listen to, can swallow you whole. It starts when you cry while reading a novel, or while watching a movie. The next thing you know, you are cosplaying at the comic con. Humankind, the species of ape that is us, was swallowed by the stories it told when it did not have a very good grasp of the way the world works.
Justice does not exist. It has no reality outside of human imagination. It only works because we make it work with the help of each other. And often, it doesn’t even work then. You don’t need me to give me examples. We all know good people who have suffered and bad people who have gotten away without punishment. Justice is a fiction that must be real if human society is to work.
So here we are. We need to believe justice exists (otherwise, what’s the point?). But we can see with our own eyes that there is no absolute justice in the world. So we push the boundaries of our story and tell ourselves that justice does exist, that the good will be rewarded no matter what, and that the bad will be punished no matter what. We tell ourselves that death is not the end and that there is space for justice to work even after a human being ceases to exist. And since the imparting of justice requires judges law enforcers, and punishers, the afterlives we imagine are full of gods, angels, demons, and divine jail keepers.