We are eagerly awaiting Daniel Dennett's book on the natural origins of religion. In the meantime, we have Richard Dawkins' take on the question. According to Dawkins, the human trait that natural selection provided was a tendency to believe whatever parents and tribal elders tell us. Uncritical credulity helped children survive and reproduce. "If you swim in the river, you'll be eaten by crocodiles." Religious beliefs have no particular Darwinian advantage, suggests Dawkins, but credulity keeps them alive and well. Certainly, no factor correlates more closely to our personal religious beliefs than the religion into which we are born.
But where do religious beliefs come from in the first place?
Start with the innate human characteristics of curiosity and awe. It is human to ask "why?" It is human to gape with wonder at the inexplicable mystery of the creation. If there is a ground for a religious response to the world, it is here -- in the awareness of and response to a transhuman mystery. (Notice, I did not say transnatural.) This is the religious instinct that Einstein, among many others, spoke of often.
But whence the gods, or God? Whence immortality, miracles and all the rest? As Piaget has shown, the default explanations of children are animistic (everything is alive) and artificialist (everything is made or caused by a humanlike agency). It is not hard to understand how these universal patterns of thought evolved by cultural evolution into the vast array of animistic and artificialist religious beliefs that we find in the world today.
The irony is, this overlay of childlike credulity in culturally manufactured dogmas very often submerges and debases the pure experience of awe that is at the heart of every thinking person's religious response to the world.
(The question of whether curiosity or awe were selected for by evolution is an open question. They may be accidental by-products of a bigger brain. Here's another book I am waiting for: Inside the Neolithic Mind: Consciousness, Cosmos and the Realm of the Gods by archeologists David Lewis-Williams and David Pearce.)