A vast literature exists attempting to explain humanity's continuing obsession with religion. See, for example, Religion Explained: The Evolutionary Origins of Religious Thought by anthropologist Pascal Boyer, and In Gods We Trust: The Evolutionary Landscape of Religion by anthropologist Scott Altran.
If I were to distill a basic if somewhat simplified (some will say oversimplified) conclusion from the sampling I have read, it is that we inherited from our animal ancestors a brain module that tends to ascribe animate agency to natural phenomena.
As philosopher Daniel Dennett explains in Breaking the Spell: Religion as a Natural Phenomenon:
A system or organization within the brain . . . has evolved in much the same way our immune system or respiratory system has evolved. Like many other natural wonders, the human mind is something of a bag of tricks, cobbled together over the eons by the forsightless process of evolution by natural selection. Driven by the demands of a dangerous world. It is deeply biased in favor of noticing the things that mattered most to the reproductive success of our ancestors.
Boyer calls this bag of tricks "gadgets" and Dennett notes that some of the patterns look like religion.
As Dennett points out, even the simplest animals have what psychologist Justin Barrett in an article in Trends of Cognitive Science 4 (2000):29-34, "Exploring the Natural Foundations of Religion," calls a hyperactive agent detection device, or HADD. For example, a clam will retreat its foot into its shell whenever any vibration or bump is sensed. Most are harmless, but the clam's motto is better safe than sorry.
More mobile animals have developed the ability to detect unusual motions that might be a predator but often is not. This tendency toward imagining invisible causes of events leads them to engage in ritual behavior that serves no necessary purpose. In a famous experiment conducted in 1948, psychologist B.F. Skinner showed that pigeons exhibit what he called "superstitious behavior" in which they engage in repeated, stereotyped patterns of conduct to get food even when those patterns are not required.
Humans have inherited the hyperactive detection device. The bulk of human evolution occurred during the Pleistocene Age, from 260,000 to 12,000 years before the present. This means that our brains today still retain the HADD system that once was necessary for our survival but no longer is needed. In his fascinating book Caveman Logic: The Persistence of Primitive Thinking in a Modern World, psychologist Hank Davis posits the following scenario:
One of your ancestors is walking through the forest and sees something on the path ahead. It might be a predator. Then again, it might be a random array of shapes and textures that amounts to nothing. If he believes it to be dangerous, he takes appropriate defensive steps. Perhaps he freezes or arms himself or flees. What's the best that can happen? He survives a lethal encounter and gets to live and function another day. What's the worst? A false positive. He finds himself with heart pounding, pulse racing, hiding behind a tree with a spear drawn for no good reason. It was only a pile of twigs on the path. He's wasted some effort and experiences a baseless fear. But he gets to go home, eat dinner, and snuggle with his mate.
Davis adds, "Perceptual accuracy was not an agenda of natural selection. Survival and reproduction were."
Since our brains have hardly evolved physically and biologically since caveman days, they retain this agency module that does us more harm than good in the modern age. We no longer have to be excessively alert when taking a walk in the woods, although a city street is another matter. In the meantime, we assign invisible agency and causality to phenomena that have no agents or causes. This leads to behaviors that are a waste of time. To make matters worse, these behaviors are reinforced by widespread social support -- by churches in particular. And, not only religious believers but scientists as well are burdened by this anachronistic brain module as they also look for causes that are not there.
Davis has this amusing but cogent summary of the situation:
There is a popular bumper sticker that addresses the problem directly. It says SHIT HAPPENS. These two words are all but incomprehensible to the majority of people. The sticker does not say I CAUSED SHIT TO HAPPEN. It does not say SHIT WAS DONE TO ME BY A VENGEFUL GOD. It simply says that . . . SHIT does happen from time to time.
This is not just an account of human reactions to everyday experiences. It also applies on the cosmic scale where great philosophers, scientists, and theologians -- as well as the typical churchgoer -- find it difficult to grasp how the universe could exist without cause. Well, modern physics and cosmology tells us that it does. The universe is an accident. SHIT HAPPENED.