It is commonly assumed that evolution tries to maximize its outcome using a greedy algorithm. In fact it seems to be a random walk across all possibilities, with unviable branches dying out over time.
Suicide may also be a second order effect of other factors. For example, suicide usually has a cultural basis: you feel some sort of shame, or maybe you think your future outcomes aren't good culturally. But that means you care about society. Therefore suicide may be an indication that we have evolved to optimize society rather than ourselves. If we didn't care about society, perhaps there would be less suicides, but it would also make humans less dominant.