Good question. Maybe some of the other Catholic posters have greater understanding of the Sacraments than I have (I hope!!) but I'll try to explain it as well as I can.
Baptism (like Matrimony or any other sacrament) has to be at least implicitly consented to. The priest asks the person to be baptized,
Do you reject sin so as to live in the freedom of God's children?
Do you reject Satan, father of sin and prince of darkness?
Do you believe in God, the Father almighty, creator of heaven and earth?
Do you believe in Jesus Christ, his only Son, our Lord, who was born of the Virgin Mary, was crucified, died, and was buried, rose from the dead, an is now seated at the right hand of the Father?
Do you believe in the Holy Spirit, the holy catholic Church, the communion of saints, the forgiveness of sins, the resurrection of the body, and life everlasting?
To each, the catechumen answers, "I do." If the person is to be baptized is an infant, his or her parents or sponsors answer "I do" in the infant's place, with the assumption that they baby will be raised in the Faith and that the affirmative answers, now merely implicit, will day by day become the baby's own.
The Church is so concerned about the consent becoming "realized," that godparents are supposed to pledge themselves to the child's religious formation, in addition to the parents, and in the place of the parents if they should die.
So if its quite dubious that the parents are living in the Faith, they can't pass the Faith on to their child.
Thus the Church's decision not to baptize under those circumstances.
And consider the alternative: if you said that, out of charity, one should baptize everybody, with or without at least implicit consent, you could take a firehose and baptize the crowds at a football stadium. Whee! Gotcha! You're baptized!
Caught myself smiling there, I'll admit. But no. (Wipes away smile.) That's not the way it works.
Thats not the way it works....NOW. But in 1858 it was OK to baptize a child without either his or his parents consent and then steal the child from his parents because they were Jewish.
I knew a priest who thought it would be a benefit to baptize all infants, was he wrong?