A way to look at this is that death is an evolutionary advantage for the species. Vertebrates have a PVN that control the HPA-Axis. As anything that contributes to the HPA-Axis such as pain, stress, or inflamation increases, the PVN shrinks and it fairly rapidly (evolutionary wise) behaves like a kill switch to the brain. Some pre-Vertebrates can effectively live forever and the mammals that live the longest have different hpa-axis loops. What is wild to realize is that there was probably a creature at some point that wouldn't die from pain until that was connected to this loop.