Morality can be involved in strategy to survive. First and foremost, morality is just specific behavioural patterns. Behavioural patterns can be encoded in DNA, e.g you could have a genetic variation that leads you to feel maximally rewarded when you fight back after some slight on your character.
Then you might wonder, "why does/doesn't every member of the species have that variation?". A suitable answer as I have come to understand is, it depends on whether it is evolutionary stable for every one to have the variation or not have it. Plus you can expect some error margins.
For example, while every one can farm, every one can't be pillaging, a society of all pillagers cannot be stable. You can also see that in a society of all farmers, a randomly introduced pillager will have a blast while not necessarily upsetting the balance. But start introducing more pillagers and the stability will break down at some ratio of pillagers to farmers.
Please note that this is not "selecting what is good for the species", that is only a consequence.
also worth noting that a society of all farmers is also not stable!
Just like how honey bees produce an abundance of honey. The moment you have any kind of abundance, something will be created to take advantage of that abundance. Nature tries everything.
All pillagers - Nihilistic, Not evolutionary stable
Some ratio of pillagers:farmers - Not nihilistic, Evolutionary stable
Where nihilism means that the society is very self defeating that it collapses instantly. And evolutionary stable means that the society can maintain it's general composition for a long enough time period.
P.S: There is probably a better word than nihilism for what I have chosen it to mean.
To the extent that humams can see the extent to which other humans have morality, genuinely having morality is a very important survial strategy. Cooperation is important in hunter gatherer bands but unlike with farmers it's fairly straightforward for people who feel imposed-upon to sneak off and start their own band. Being seen to be immoral is a good way to end up dead, either killed or from dieing along the next time you become injured or sick.