There's this thing that happens with evolution. Imagine you have a rando population of anything, say frogs, and they range from "do not care about sex" to "OMG sex" and they randomly meet at the local pond. If that trait about how they feel about sex is genetic and passed on to their children, you can forecast over time how that trends in future generations.
There's likely a separate trait that ranges from "babies are dumb" to "OMG babies" that is also random, also genetic, and has its own trend.
The net result is frogs who don't really care about sex and don't really care about babies (OK, probably a bad example) are less likely -- just from the roll of the dice -- to have a zillion great-grandbabies. And this plays out across a zillion different species with a zillion different stressors and constraints so that you end up with "I like big antlers and I cannot lie" and "I'm too sexy for this dance" and all the other things that indicate to a potential mate that either the sex is worth it or that the babies will be strong like bull.
#IAmNotABiologist[EDIT] TL;DR If it can be passed on, and doesn't negatively affect the chance the next generation will breed, it will be passed on. Wash, rinse, repeat.