Think the prisoners' dilemma and other scenarios like that. Individuals tend make decisions that maximize their own welfare. But when in a group setting, sometimes the individual decision can be detrimental to the group survival. And when your group is killed off, the fact that you got an extra dollar/egg/berry during that moment you maximized your own welfare is irrelevant. There are evolutionary forces acting not only on the individual but also on the group.
I would agree that group survival has almost certainly played a role in human evolution. We believe, for example, the the Neaderthal species may have been outcompeted into extinction by H.sapiens because of factors related to group management. But we also have evidence of religious type behavior by Neanderthals so it is not the practice of"religion" that confers an advantage.
Let's ignore all the details about religion and just focus on the most important one -- there are invisible beings all around watching us and judging us. Researchers are finding that when people believe somebody or something are watching them, people tend to cheat less. In one experiment, 3 groups of kids were tested. Those who were told a magic fairy was watching them acted just as if an adult was in the room watching them -- while the last group (neither adults nor fairies watching) cheated far more. So what religion likely did in our ancient past was to motivate individuals to engage in better group survival behavior.
Don't change subject because you can't support your claim. You originally said that there is evidence that religion confers an evolutionary benefit. I don't think there is any good evidence for that. It would be the kind of thing that is virtually impossible to defend. I'm sure there are claims like that by religious people seeking some scientific justification for their beliefs. But I can't imagine he experiment that would test that claim with scientific rigor.
Now, we do know that social justice and concepts of guilt exist in the animal kingdom and in our closest relatives. Anyone who has owned a pet dog or cat has undoubtedly seen guilt, fairness, and social justice concerns. Ever come home to trash scattered around the house and a dog that is making himself scarce? Ever try having two dogs and giving one a treat in front of the other? Chimpanzees will hunt down and kill a member of their group that commits a serious offense but also help feed injured members of their group. And these things are beginning to be tested using scientific methods. But this has absolutely nothing to do with religion. Even if a religion preaches the same principals, you are following a logical fallacy to then say that religion has anything to do with it.
Let's take guilt for example. Guilt might have evolved to make individuals behave in a way that is conducive to group survival. Let's say it is true that guilt confers an evolutionary advantage. If a religion then makes guilt a major tenet and uses it to control congregants (as several major religions do), that does not mean that religion is offers the advantage. It's like saying compounds in red wine are healthy and therefor being catholic and taking communion every Sunday is an evolutionary advantage. It simply does not follow logically from the evidence.
The concept of thoughts and behaviors being inheritable sound strange but don't underestimate the complexities of the brain. An ancestor in our past with some gene that caused his brain to fire off pleasurable sensations when he/she interacted with others in certain ways would have been more proned to continue to do those interactions. And if those types of interactions contributed to group survival, it would then have been more likely for those characteristics to be passed on. You might say it's not the religion itself but the tendency for brain have pleasurable sensations in the presence of religion that may be genetic.
You are right that thoughts and behaviors do seem to be somehow stored in our genetic code in a way that we do not currently understand. The implications of that are extremely interesting but so far our understanding is so rudimentary that almost any discussion about it is speculative. And think about butterfly migrations. Large groups of monarch butterflies migrate down to central mexico...but the migration occurs over several generations. Understanding how the butterflies know both the route and their particular generation's part in it is completely baffling.
And as for evolutionary advantage, ants kick our ass. The weight of all the ants in this world is greater than the weight of all humans. They were on this earth hundreds of millions of years before us and will be here hundreds of millions after. Exactly how much is our intelligence an advantage on this time scale?
How intelligent are we? I have to go to work every day, Go out and buy and then prepare my food,etc. My cats just lay there and have everything done for them. So who is smarter?