Religious belief is an evolutionary accident
Humans generally have an understanding of their physical and social world and these abilities develop at different rates during childhood. It appears that we share the physical understanding with many other animals, but the social understanding is more specific to humans (and a few other animals). However, these cognitive functions are imperfect and sometimes lead to erroneous conclusions, including an agent detection bias and an unjustified belief in dualism. This gives rise to a tendency for people to believe in religion.
"But these systems go awry in two important ways that are the foundations of religion. First, we perceive the world of objects as essentially separate from the world of minds, making it possible for us to envision soulless bodies and bodiless souls. This helps explain why we believe in gods and an afterlife. Second, as we will see, our system of social understanding overshoots, inferring goals and desires where none exist. This makes us animists and creationists."
- "Once we realise this omnipresence of the imaginary in the everyday, nothing special is left to explain concerning religion "
- "As soon as you have theory of mind, you have the possibility of deceiving others, or being deceived "
However, all evidence in psychology and neuroscience suggests that dualism is incorrect. Minds never occur separately from bodies.
Our inclination to see intelligent agents everywhere is probably the explanation for the intuitive appeal of creationism.
Religion is a costly activity
- "If people literally applied counterfactual religious principles and prescriptions to factual navigation of everyday environments they would likely be either dead or in the afterlife in very short order-probably in too short an order for individuals to reproduce and the species to survive. "
Evolutionary theory predicts that detrimental traits, such as religious tenancies incurring a cost, would become progressively less common in later generations due to natural selection unless they are counter-balanced by some evolutionary benefit. Various theories of a direct evolutionary benefit have been advanced, including: intellectual benefits, emotional functions, it regulates socio-economic activity, etc. The other school of thought is that religion is a side effect or by product of our species development that had other evolutionary advantages. 
Among animals, humans have large brains compared to their body size which has been linked to social and cognitive abilities. This may have arisen because of the evolutionary advantage of improved social ability or language use with a tribal group. It also may have occurred because it enabled tools to be created and used which provided an evolutionary advantage. The need for social skills and language may have grown out of the advantages afforded by social living. It may be that the social bonding aspects of religion provide a direct evolutionary advantage in this context. Alternatively, since evolutionary development tends to be rather hodge-podge, humans are prone to many cognitive biases which may have inadvertently predisposed them to religion.
The exact mechanism for religion to occur has not been conclusively determined and research is ongoing.
- Is theistic religion a consolation?
- Religion is the social bond in society
- Religion provides an evolutionary advantage