The "comfort" of religion
The obvious way that religion "comforts" people is by reassuring them that death is not really the end of their existence. This, I suspect, is the main reason why religion has taken such deep root in the human mind for so long, and why religious people often react with such irrational resentment when it is challenged. A little thought, however, reveals a serious danger. Insofar as a person believes death to be less final and terrible than it actually is, he will place a correspondingly lower priority on avoiding it, which may translate into taking risks he would never otherwise take. This is not just theoretical. There was a period in my life when I was seriously contemplating suicide. If I had believed that death would be followed by an afterlife, perhaps pleasanter than the present one -- well, I might very well not exist today.
More generally, false beliefs almost inevitably become dangerous if a person believes them strongly enough to act on them. I would find it very comforting to believe that I had a million dollars in the bank, but if I genuinely believed that, and began acting as if it were true, I would quickly run into all kinds of problems which could have been avoided by accepting reality.
The danger of increased risk of death due to belief in an afterlife applies on a species-wide level as well. The reason most humans have clung so desperately to this comforting idea for all of known history is that death was inevitable -- everyone eventually died, no matter what they did. Now that we're on the brink of a technological solution to the problem, one of the obstacles we face is a visceral discomfort with the idea of eradicating death, rooted in that "comforting" belief that death is not so terrible after all and is, in any case, God's will. Even many atheists have adopted a philosophical and rather bovine (and unconvincing) passivity in the face of death, as a substitute comfort belief to replace the afterlife; and this too is sometimes an obstacle, though in general a higher proportion of atheists embrace transhumanism than of the general population.
(There is one life-after-death scenario I consider somewhat plausible, but only a fool would count on this actually happening, and it has nothing to do with religion.)
Another "comfort belief" of religion is that problems in general are less urgent than they seem because there is a deity watching over us and protecting us, or because what appear to be problems are part of a divine plan. Again, the danger inherent in such ideas is obvious -- why take concrete action against a threat if a higher power is protecting you against it anyway, or if it's all ultimately for the best? We can see this concretely in the American fundamentalist disdain for protecting the environment -- they really believe that God won't let anything too terrible happen to us no matter how badly we damage the planetary life-support system (I've seen the story of God's rainbow promise to Noah invoked in this context), and/or that it doesn't matter anyway because Jesus is coming back soon. People who sincerely hold such beliefs are endangering themselves -- and the rest of us who have to live on the same planet with them.
Finally, let's not forget the real purpose religion has usually served historically -- social control by elites. Most religions don't stop at providing comforting beliefs -- they also have a priesthood of some sort which claims to know, or even to be able to influence, what sort of afterlife ordinary people will have, very often based on how submissive they are to the dictates of that same priesthood. This confers incredible power over whole populations of dupes, without even any need for the usual uniformed thugs to enforce it. Thus even the supposed "comfort" beliefs have in practice more often been instruments of fear and control. And those beliefs are revealed as being not merely an error, but rather a shabby, cynical lie, fabricated to manipulate those who believe it.