If in a hunter-gatherer society most people stop reproducing after 40 (not entirely realistic, but bear with me), me being alive and fit at 45 can still improve the survival of my genepool. I can hunt meat and gather plants to make sure my children and grand-children are well-fed and able to produce plenty of offspring, carrying my genes on. I can build shelter, care for the young (improving their survival chances and freeing up the parents to do more physically demanding work).
And my siblings share half of my genes, and my cousins a quarter (assuming no inbreeding at all, otherwise the numbers go up). So helping their children survive and proliferate is a win for the proliferation of my genes. Evolution gets less effective the more indirect the effect and the lower the gene contribution, but it doesn't completely stop working. If there is one clan where everyone dies at 30 and one where people stop reproducing at 30 but stay useful members of society until 60 then then the second clan will do better and outcompete the first