Due to evolution, our bodies produce and release hormones which make us happy when we love or do good to others, or feel empathy towards others.
Let us see this scientific study, which shows that the origin of morality is innate:
Is there an innate moral sense? Scientific evidence, from child development, linguistics, and behavioral economics to neuroscience, moral psychology, and primatology reveals universal drives that constitute a biologically prepared moral architecture within human nature. This innate moral sense is akin to the innate predisposition for smell or language and suggests human beings are born with the prototypes of a sense that fosters anxiety when they witness others in distress and, similarly, promotes positive feelings when that distress is alleviated. Incorporating the concept of an innate moral sense into our models of social and political life would improve ethical analysis.
Nobody tells a baby how to love his/her mother. These are the hormones which are making a baby love his/her mother automatically.
Shortly after you give birth, your doctor will place your baby against your chest. This moment of skin-to-skin contact is important — and often overwhelming — for both mom and baby. Feeling your touch and hearing your voice calms your baby and makes him feel safe. During this skin-to-skin moment, your body releases oxytocin.
In particular, when women give birth, there's a big surge of oxytocin, and oxytocin is also released during breastfeeding.
Oxytocin has been called the "love hormone," even though its effect isn't always that lovely. It's thought to deepen the bond that a mom has with her newborn. But what about the dads, who don't get pregnant or breastfeed? It turns out that a father's interactions with his children produce a similar rise in oxytocin levels.
Researchers have found that emotionally involved fathers feel other hormonal effects: higher levels of prolactin, a lust-squelching hormone that shows up in women during breastfeeding and in men after sexual climax; and higher levels of vasopressin, a hormone linked to bonding as well as the maternal stress response.
It turns out that fathers get many of the same rushes that mothers do from parenthood — but the payoff depends on proximity and interaction. For example, researchers see the effect if the child sleeps with the parents if the father recognizes and responds to the baby's cries if Dad plays with the kids. When that proximity isn't present, the fatherhood effect isn't as strong.
Even when we are grown up, our minds decide if any action is good or bad on the basis of this empathy i.e. if we are doing good to others with our actions, or if we are hurting them with our actions.
Of course, later, there are other factors involved too like social upbringing, religious brainwashing etc.
Therefore, in an adult person, morality is no longer completely innate. An adult person's own moral views are influenced primarily by three things: empathy, enlightened self-interest, and social pressures.
In the case of babies, instincts such as empathy and trust in the parent are a larger influence on their morality than they might be for an adult, and due to the lower intelligence and perceptiveness of a baby, the social influences on their morality are weaker than they will be as the child grows and begins to interact more with society.