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.