I’ve heard a lot of atheists hypothesize that one of the reasons religion was invented was because people had to manage their fear of death. If people believe that they will continue to live on in some fashion after death, it mitigates their fear of death. Can the fear of death explain the origin of religion, or the origin of religious faith in people today? Perhaps, but three points should be made.
First, not all religions include conscious existence beyond the grave. For example, in many Eastern religions absorption into the One (personal extinction) is the end of all things. Clearly immortality is not the motivation for those religions and religious practitioners.
Secondly, so what? Even if the origin of religious belief in humans is motivated by a fear of death and desire for personal immortality, that tells us nothing about whether or not religion is true or false or whether there is life beyond the grave. Maybe humans fear death because it is unnatural (having originally been created by God for immortal life), and maybe humans desire immortality because we are immortal souls. Simply identifying a motivation to believe X does nothing to tell us whether X is true or not.
Thirdly, not all believers who follow religious traditions that offer immortality necessarily want immortality, and not all believers who follow religious traditions that offer immorality chose to follow that tradition because they feared death and/or wanted immortality. In the way of a personal testimony, while I think heaven will be a great place, and I’d much rather go there than go to hell, I did not become a Christian because I feared death or wanted immortality. Truth be told, part of me would prefer personal extinction upon death rather than an afterlife.
So for all the atheists out there, when it comes to debating religion, focus on trying to demonstrate that religion is false before you try to speculate as to how people came to believe false ideas. Put another way, philosophize before you psychoanalyze.