Religion is likely just something that was created to bring people comfort, community, and meaning in life. I feel like God is just a man-made concept we created to explain how our universe came to be and the afterlife is likely nothing more than something else we came up with to comfort ourselves. People don't like uncertainty or the unknown, it makes them uncomfortable. As a result, we sometimes may attach ourselves to anything that may explain what is going on and once we have made up our minds and have invested enough time upholding said explanation/belief then it can be hard for us to let go of it.
I have doubts about there being a God or Gods, and I also have doubts about there being an afterlife. The afterlife bit doesn't even make much sense to me since your entire being is the result of your body, especially your brain. Your sense of self is just a product of neural activity so I don't see how there could even still be a "you" once the literal thing needed for your existence is gone.
The afterlife is a common concept in most religions, which makes sense since people tend to look to religion for comfort, guidance, and explanations on life and the way the world works. This probably results in the theme of there being an afterlife coming up a lot since it can be used to satisfy all three of those things and more. Death is scary for most people because it is not an experience you can go into knowing what will happen and what it will feel like. You've only ever experienced being alive, after all. The afterlife is a concept that provides comfort to most since it would mean that they don't have to fear the unknown anymore. It can allow for many to be freed from the shackles of existential dread and better cope with the inevitability of death. There isn't any evidence of there being an afterlife, of course, and I doubt there is one. I think that it's more likely that there isn't anything after death and I don't see it as a bad thing. Death is like being rewarded for having put in all that work to stay alive by allowing you infinite rest.
I know this just me blabbering on about the same bullshit that has been repeated by many over and over again, but that's honestly just my basic ass take on the matter.