So if you didn't mean the usual metaphorical notion of, "was selected for by natural selection because it increased evolutionary fitness", what did you mean?
I think the prior poster may have been making a point more along the lines that depression is a downside of having benefits like neural plasticity or something, not that this disease state is necessarily beneficial in itself. More like how the downside of having high-performance tires is poor rain traction or something.
The trait is passed on because it benefits the species. You have to consider more than individuals in the evolution of social animals. In various circumstances some organisms will eat their own offspring. Obviously the "infanticide gene" if considered alone, would not make evolutionary sense, yet there it is.
Group selection is a possible mechanism in social animals, but it requires the group to be strongly interrelated relative to the rest of the species, and it relies on the group being able to expand at the expense of the rest of the species.
Infanticide makes perfect sense; offspring are only related 50% to the parent, so if resources are less than 2x as effective in the bodies of offspring compared to once they have been digested by the parent, of course they should be consumed. The genes of the offspring won't agree, of course; for them the calculation is reversed.