In order to answer this question let us take a look at why dharma is needed in Samsara. Why can't we just have artha and kama as goals in samsara?
Bhishma on Dharma
Bhishma said, ‘..it is difficult to say what righteousness is. It is
not easy to indicate it. No one in discoursing upon righteousness, can
indicate it accurately. Righteousness was declared (by Brahman) for
the advancement and growth of all creatures. Therefore, that which
leads to advancement and growth in righteousness. Righteousness was
declared for restraining creatures from injuring one another.
Therefore, that is Righteousness which prevents injury to creatures.
Righteousness (Dharma) is so called because it upholds all creatures.
In fact all creatures are upheld by righteousness. Therefore, that is
righteousness which is capable of upholding all creatures. Some say
that righteousness consists in what has been upheld in the Srutis.
Others do not agree to this. I would not censure them that say so.
Everything, again, has not been laid down in the Srutis.’
[This refers to the well-known definition of Dharma ascribed to
Vasishtha, viz, “That which is laid down in the Srutis and Smritis is
Dharma.” The defect of this definition is that the Srutis and Smritis
do not include every duty. Hence Vaisishtha was obliged to add that
where these are silent, the examples and practices of the good ought
to be the guides of men, etc.]
Mahabharata, Santi Parva, Section CIX
Dharma is necessary to prevent injury to creatures and to uphold all creatures.
How do we apply dharma in the case of a mother giving birth to the child? The first priority is of course to save the lives of both mother and baby.
What should we do when the doctor thinks that only one life can be saved either that of the mother or that of the baby?
Obviously from the point of dharma we have to make sure that our decision is not cruel to either the mother or the baby. At the very least cruelty should be minimized. This is also the spirit of the three quotes given below.
However, discard the desire (kama) and material wealth (artha) if
contrary to Dharma; as also, any usage or custom or rules regarded as
source of Dharma if at any time they were to lead to unhappiness or
arouse people's indignation.
Manu Smriti 4.176
When must holy acts not be done?
If a holy act is against the interest of other members of the society,
it should not be practiced. It is Dharma which is the source of Artha
and even of Kama.
Kurma Purana I.2.54
Attitude towards ancient custom
One should practice what one considers to be one’s duty, guided by
reasons, instead of blindly following the practices of the world.
Mahabharata Santi Parva Section CCLXII
So the question boils down to whose death will be more cruel, that of the mother or that of the baby. Who will suffer more? How do we minimize cruelty? The answer is that the mother's life will get priority over that of the baby. The reason is that the mother will suffer more when she realizes that she will die than the baby.