Actually, the Church does not teach we should always save the child. This is what in moral theology called the “double effect”. You may want to first read on it online.
The double effect refers to when a moral decision would at the same time cause harm to another person; for example, saving the mother’s life would endanger the fetus, saving any one of a siamese twins would mean death for the other, ensuring the health of a fetus would preclude cancer treatment to the mother, etc. A decision has to be made to save one of the two or more affected, but the other will be harmed or may even die.
The teaching of the Church in this case is that we must try to treat the problem and try to save life the best we can. Any intentional harm, any direct or intentional procedure to harm or terminate a life must not be used. If in the attempt to save one, another’s life cannot be sustained despite our best efforts, we have to trust that the matter is in God’s hands.
For instance, in the example you gave, the doctor could try to extract the fetus at the very last instant before the mother’s life cannot be saved. All attempts to sustain the fetus outside of the mother should be employed with due diligence. And should it expire, we know that we have tried our best.
Conversely, the mother, being the one who has the ability to choose, can choose to sacrifice her own life. The doctors instead can do all they need to save the fetus first, knowing that the procedure involved may lessen the chance for the survival of the mother. Due diligence for saving the mother’s life of course should be employed once the fetus is safe.
However, it is always immoral to intentionally terminate the fetus, either by chemical, mechanical, or any other procedure or means. Neither would it be moral to do the same to the mother.
Some finer distinction: in trying to remove the fetus, the doctor realizing the mother’s heart is dilating, may not be able to apply the necessary medicine since it would affect the survival of the fetus. The delay subsequently causes the mother’s life. This is unintentional and cannot be helped despite our best effort. Another example: in stopping the bleeding inside the mother, it is unsafe for the fetus to remain inside. To take it out necessitates removing his sustenance and as a result could cause irreversible harm. This is unintentional but cannot be helped.