Something as pervasive as religion, which is found in every human cultural group, must have an evolutionary explanation. I assert this without proof, but I trust that most scientists agree with me. Even though religion must have served a useful function to enhance fitness in the past, today it might serve no useful function.
Or does it?
I will present three functions of religion.
First, it facilitates altruism. This is a good thing. Altruism is an instinct in animals, especially in humans. But how can you be altruistic? Religious groups provide ways of doing so. Give them your time and money, and they can direct it toward people who need help. It certainly beats walking the street and looking for people who need help. One example is that poor rural villages in Africa need clean drinking water even more than they need advanced medicines. Civil engineers can join a religious organization that sponsors them to install wells in rural villages. (You can’t just dig a hole in the ground. Surface water would contaminate it. Rural villages need civil engineers from advanced countries to help them have healthier lives.) As far as I can see, this is pure altruism. Thank God for this kind of religion.
Second, it impedes the discovery of truth. Throughout history, religions have suppressed truth. So far, it has always been temporary. The Catholic Church persecuted Galileo, but they now celebrate him. By 1843, the cathedral at Strasbourg had an astronomical clock (Horlogue Astronomique) that celebrated the Copernican system it had condemned three centuries earlier.
Religions eventually embrace truth but only after sometimes centuries of resistance. I used to be a member of the American Scientific Affiliation, a group of Christians in the sciences who meet together to confront scientific and social issues from a Christian perspective. After immense angst, they usually end up embracing concepts that other scientists had long before accepted. Never has the ASA presented any new perspective on science. I finally left because I got tired of the endless angst that these fine people put themselves through (usually internal, rather than external, conflict) for reasons that were ultimately unimportant. Thus, I conclude, even good religion impedes the discovery of truth.
Third, it makes money for religious leaders. This cannot explain the origin of religion, for it only works when altruistic and other instincts are already in place. Charismatic leaders who use religious devices can brainwash people into following them, giving them lots of money, and ignoring the times when they are discovered to have moral failings that they condemn in others. Examples have filled books. This continues because people still have an instinct for credulity, to believe religious leaders, even after repeated proof that many of them are frauds, and there is so much money to be made that there is a big intake of new fraudulent leaders. I used to be in one such cult, and know what it feels like to slowly and painfully extract myself from it.
Religion is part of our nature and will not go away. We need to be aware of it and allow only its good functions to operate.