The prison population is more religious than the population at large. I don't have the numbers at my fingertips, but it's a stat I've come across before.
And if I were in prison, hoping to be paroled, you can be sure I'd be acting religious as well.
I don't know anyone who's religious because they're scared of getting murdered. I do, however, know tons of people who are religious because they were raised that way. This isn't scientific, but it leaves me with little doubt which is cart and which is horse.
People are religious because they were introduced to it, AND because they find it helpful in their daily lives. I'm sure there is both nature and nurture involved. I agree with Ax that fear - or the lack of security in one's life - can lead to dependence - whether that is dependence upon religion, nationalism, other -isms, superstition, or just the fundamental certainty that there is such a thing as certainty - that brings some sense of security to one's life.
When the natural world makes no sense, and seems to be random and violent, then having an ally in someone or something super natural (literally above nature), can be very comforting. I've studied my Tlingit Indian culture and found that, several generations ago, life was ruled by the whims and vagaries of the supernatural, and had to be considered and appeased at all times. But nowadays, people like me can go for hours - maybe even days - not thinking about how an insulted animal spirit or wind spirit or mountain spirit is going to get me for my incorrect behavior, by causing a famine, storm, or rockslide. Likewise, I've been raised Catholic, but I no longer believe that discussing religion the way I am now is likely to cause me to be struck by lightning or the trials of Job. I do not say "there but for the grace of God go I" when looking at people in poverty, because I don't feel the smugness of being in the grace of God, or anyone else. Instead, I see social injustices brought on by poor public policy.