I believe this was one of the main points of Dawkins' The Selfish Gene: https://en.wikipedia.org/wiki/The_Selfish_Gene
If you know you can't pass on your own genes, then the next best thing is to pass on the genes of your family or close relatives. Committing suicide may (or may not) make that more likely.
I don't think there is necessarily an evolutionary reason for suicide, but it certainly seems to fit within an evolutionary framework.
Do you really expect that a get-depressed-and-die instinct would reliably result in at least that much benefit to someone's close kin? If not, then you don't really expect such an instinct to evolve by kin selection.
If we suppose that people only consider suicide in bad situations, where, say, their expected reproductive capability is maybe 1/8th that of their surviving relatives, then the evolutionary cost is 1/8th of what you assume. In this case, you would only need to save one cousin, or to have 1/4 of a chance of saving a sibling, or 1/2 a chance of saving a niece/nephew. Or maybe not "saving" a niece, but making it practical for your siblings to deliberately have another niece. ... The scenario remains questionable, and the 1/8 is of course made up, but it does seem possible.
Consider the case of cancer. Cells have builtin functions for commiting suicide when something goes awry, and also do not breed excessively normally. However since knocking those inhibitions out is advantageuos in the short term, cancer arises again and again. The mutations seems to confer an advantage, for the first generation, the second generation... quite a few generations actually. Then suddenly, as the cancer cells reach critical mass, and the parasite/parasitee ratio grows to large, it becomes a huge liability. The cancer cells die. Every single one. The end.
It's very well-documented that there are some genes that can be adaptive in some situations and fatal in others. For example, sickle-cell anemia is highly adaptive in sub-Saharan Africa where it confers immunity to malaria, yet results in debilitating blood clots when expressed in some individuals. Suicide is the mental version of this: not a genetic trait in itself, but a side-effect of a collection of genetic traits that are usually beneficial in isolation.