Why do suicide has been kept in natural selection?
This assumes that tendency to suicide is hereditary. It seems that currently, the consensus is that suicide risk can be increased by environmental factors as well as by family history, so it may only be partially encoded in our genes.

For that part of the 'suicide genes' that does survive the natural selection, some of the possible explanations could be that people who commit suicide may have already had children, so their genes have been passed on to the next generation.

Another explanation could be, linked to what Yuval Noah Harari mentioned in "Sapiens". Hunter-gatherers were constantly on the move and it was not uncommon for them to kill or leave behind the elderly or individuals who would otherwise be a burden or slow down the tribe. It became a social norm, potentially to the point where the sick individuals would be ready to commit suicide themselves. The tribes which practised this were able to hunt and gather more, increasing their chances of survival.

All this is, however, a speculation, it is very hard to prove the evolutionary causes of suicides under scientific rigour, especially when running a controlled study is almost impossible. Even if we were able to run a controlled study, we'd most likely find that there is a large number of factors that allowed suicide genes to prevail.