Religion seems to be a poorly understood phenomenon. Like art it expresses things we know but can't yet articulate.
Like traits that have been selected for in physical evolution it operates in a selection space, just not the physical selection space. It operates in the abstract environment that defines culture. That is not to say it doesn't have an affect on physical evolution. To understand that you have to understand group selection. Religion reinforces group cohesion in much the same way art does. The pyramids while ostensibly religious are a form of art that strengthened group cohesion. They say we are a superior people.