The evolutionary reasoning for altruism is that helping one person for a small detriment to yourself as a group makes it more likely that you will be helped out at a later date. Being a good and moral person allows you to live in a world where you are surrounded by good and moral people. However, in a world where nobody is good and moral, being good and moral is disastrous. As Mal on Firefly put it in Our Dear Mrs. Reynolds, "If somebody tries to kill you, you try to kill them right back!" -- However, if nobody tries to kill you... you should never try to kill others. The best strategy is the strategy other people are using. If they are moral, be moral. If they are not, don't be moral. This however leads to an odd sort of chicken or the egg problem. Who are going to take the moral, less successful strategy enough to make it more successful for everybody involved?
Altruism—benefiting fellow group members at a cost to oneself—and parochialism—hostility toward individuals not of one’s own ethnic, racial, or other group—are common to human nature, but we don’t immediately think of them as working together hand in hand. In fact the unexpected combination of these two behaviors may have enabled the survival of each trait according to Bowles and Choi.
In a state of war, you are united against outside threats, xenophobic and altruistic.
Aggression consumes resources and risks death; altruism, particularly toward those with whom we have no direct relationship, has the effect of helping other genes advance at our expense. But parochial altruism could have evolved if parochialism promoted intergroup hostilities and the combination of altruism and parochialism contributed to the success of these conflicts.
So by promoting a sort of tribalism and intergroup warfare, rejection, fear, and non-cooperation between the groups, the intragroup altruism becomes much more likely to be returned to the benefit of everybody (within the group). If you can isolate your group with respect to other groups, you both need to work together in order to succeed in these conflicts and can work together due to the much greater assurance that your gesture will be reciprocated.
In a state of war, when xenophobic and altruistic, you can swing the optimal strategy strongly toward the altruistic side to the advantage of the entire group.
Without warfare a general altruism works quite well for all groups involved. In a world without any trusting capital where everybody is distrusting and altruism is too rare to make altruism a viable strategy. The best way to get to a state where altruism is the norm and killing people isn't a viable strategy is to form a small group and kill OTHER people.
From a state of nature, where the life of man is solitary, poor, nasty, brutish, and short to a more peaceful altruistic world... the best path is via a small warring group where everyday is the day after 9/11. Where everybody is xenophobic and altruistic. Where you love your neighbor as yourself, but take slaves "of the strangers that do sojourn among you."
The best way to build up some trust within a group larger than your family is by forming a group, go around murdering other people, enslaving them and insuring xenophobia. This, oddly, leads to altruism. You keep people out and help people in, and can succeed in tough times and help in good times, and your entire group will be the better for it.
Eventually expanding this to the point where the group boundaries break down and altruism becomes more universalized. Although it might help if we were attacked by aliens.
Genocide, xenophobia, hate, religious bigotry, and god-justified wars may actually be the birth pains of universal altruism. We happy few, we band of brothers, we group of soldiers about to go off and kill... may be the seeds of societies like ours where killing people or stealing things is a very ill advised strategy.
(via Science and Reason, which has some points worth reading on the religion aspect of this.)