If a pregnant woman craves a certain food on Yom Kippur, we assume that the baby wants it and that withholding it puts her and the fetus in danger. Therefore, they feed her that food until she feels better.
A sick person on Yom Kippur - if the experts say that he would be in danger if he does not eat, they give him food. If there are no experts there - they ask him. If there is a disagreement between him and the experts, his opinion wins.
In general, one can violate any Torah's prohibition to save a life - with three exceptions: idol worship, illicit relations, and murder. Where do we learn this from?
Idol worship. The words of the "Shema" - "You shall love God your Lord with all your heart, all your soul, and all your possessions" mean that one should give up his soul or possessions but not worship idols.
Murder prohibition is derived from logic. If a governor tells one to kill a person or be killed himself, one should allow himself to be killed but not become a murderer. How does one know that his blood is redder than that of the other person?
Connected to murder is the law of prohibited relations: a betrothed maiden can be saved from rape at the cost of her pursuer's life. "The betrothed maiden cried out, but there was no rescuer" - had there been a rescuer, he would be allowed to save her even by killing the assailant. However, if he can stave the attacker without killing him, he would be obligated to do so.
Art: Children eating a pie by Bartolomé Esteban Murillo