Someone pointed out that a bear is not going to say, I am going to have sex because I want to be a mother. Animals are guided by their own bodies to do what is needed to perpetuate the species so it does not become extinct. If a species does not evolve the ability and/or the motivation to have sex, then it will simply vanish from the face of the earth. It is the hormones inside a bear's body that makes it want to have sex, by stimulating its sex drive. And other chemicals will make her do it repeatedly over a period of several days because it is pleasurable.
Mammals have the hormone oxytocin that makes them feel good if the hormone is released into the brain. Oxytocin is released when a mammal has sex, and when a mammalian mother cares for her baby. Oxytocin is also released in large amounts during child birth, as it helps prepare the body by stimulating the muscles that are used during childbirth. Therefore oxytocin probably evolved originally for other purposes, but it has been hijacked by the body to encourage animals to do what is good for the survival of the species by releasing oxytocin to make an animal feel good when they do the correct things that are needed for survival.
When a female is about to give birth or lay eggs, her body once again releases the appropriate chemicals to make her do the right thing. A turtle will become restless and she will go on land, find a hole and lay her eggs. A mammal's body will release hormones to stimulate milk production and also the maternal instinct. The maternal instinct is so strong that a mother will often adopt animals that are not her own species, such as a dog adopting a tiger cub as one of her own and feed it milk.