As far as I understand, it's all bound up with the process of evolution. We can call those two traits- to live and reproduce, instinct. Over a timespan of billions of years, where creatures are running through their life cycles and chance is making very small changes in their DNA. Some changes take, some don't. The creatures who seem to do better are changing via adapting to their environment.
One of the fundamental things the creature needs to be able to do is live long enough to reproduce. And obviously, the creatures that got landed genes that made them want to survive and shag everything in sight had a lot more chance of passing those genes on.
For some animals- that's still apparently enough. Female octopus stop eating after laying eggs and die before they hatch. Other creatures presumably 'found' that sticking around to look after their children gave their children a better chance to survive and reproduce themselves.
What I certainly find interesting in humans is that we don't generally seem to lose the instinct to survive. Even some 80 year olds who couldn't possibly bear children (although, I guess men still can.) Are likely done parenting them, still have the instinct to carry on. I guess though, we are related to animals that live in social groups. So- the grandparents do still help in raising children- their genes effectively. Why childless people still have this instinct though, I'm not sure. Maybe because we still have the biological ability to have children.
I think it's very interesting that we can overide this instinct though- like you say, with our conscious, reasoning mind. I'm not sure many other animals can. That certainly puzzles me because, is it within our evolutionary best interests? Maybe it is though. Terrible to say but, some of us are also not wanting to reproduce because we don't think our genes and even our defects made us well suited to this world. Maybe antinatilism and ideation do fit in to evolution because they 'weed out' those who at least don't feel- maybe aren't suited to thrive in this world.