Selection works on the level of the genes. Dying without procreating can still be advantageous if doing so means that enough of your relatives survive, for example. https://en.wikipedia.org/wiki/Kin_selection