I think different people could come up with many explanations here.
The author thinks the baby cries out of empathy for the sorrows (or hunger, discomfort ) of the other baby. This may be, if we think of a very simple form of empathy.
2: the action of understanding, being aware of, being sensitive to, and vicariously experiencing the feelings, thoughts, and experience of another of either the past or present without having the feelings, thoughts, and experience fully communicated in an objectively explicit manner; also : the capacity for this.
But then the baby would also cry if he heard another loud noise that he found stressful.
I can imagine that the cries of baby 2 remind baby 1 of times when he himself felt upset. Baby 2 may not really share the suffering of baby 1, but feel distressed that this might happen to him again.
I wouldn't put it like Chris, that nature has selected babies to cry when they hear another baby cry, it would be hard to imagine that this much has been programmed, I imagine the reaction is partly automatic and partly a sign of the emotional development of the baby.
If there was a loud noise, or a baby two was crying, and baby 1 was not deaf and yet did not respond in any way, there would be something wrong with him.