A popular - if facile - argument is that religion is poplular because people are scared of dying.
A counter argument is that the grand-daddy of the Abahamic faiths - Judaism - had no notion of posthumous existence. The most familiar expression of that is in Matthew 22:23 "The same day the Sadducees, who say there is no resurrection..."
AFAICT belief in an afterlife remains widespread but not universal amongst Jews today.
Early Judaic writing is sometimes ambiguous as to whether death is or is not permanent oblivion, but there is scant support or the idea of posthumous reward in heaven or punishment in hell. All - rich and poor, good and evil all have the same fate of 'sheol'.
Ecclesiastes 9:2 "2 All share a common destiny—the righteous and the wicked, the good and the bad,[a] the clean and the unclean, those who offer sacrifices and those who do not."
The idea of an afterlife more familiar from a Christian perspective appear in later writings, almostcertainly the result of syncretism from Greek ideas. An example is Daniel 12 “Many of those that sleep in the dust of the earth will awake, some to eternal life, others to reproaches, to everlasting abhorrence” — implies that resurrection will be followed by a day of judgment. Those judged favorably will live forever and those judged to be wicked will be punished."
Ancient mesopotamian legends also say almost nothing about an afterlife. There was no heaven for dead babylonians to look forward to!
in contrast, the Egyptians took great pains to ensure the afterlife was comfortable - at least for the rich and powerful. But the Jews had little time for Egyptian religious notions!
In hinduism, re-incarnation would seem to be a palliative for death's sting, but a pious hindu does not seek to re-incarnate. Life is a punishment, and the goal of Hiduism is the peace and oblivion of nirvana.
In Christianity,the idea has developed to the point where earthly life is reduced to a mere testing ground. In Christianity, there is a strong tradition that suffering is good, because it leads to posthumous rewards. Presumably that has roots in Greek ideas about the grossness of flesh and the fact that early Christians tended to be poor - hence their inescapable suffering at the hands of grasping landlords and corrupt priests could presented as a positive.
All in all, it is overly simplistic to suppose religion exists because people are scared to dying.