In short, touching that happens inside doesn't matter. Even if you swallowed an impure ring and a pure ring and they touch each other in your stomach and then you throw them up separately, the pure ring stays pure. (Rambam, Tumat Met 25:12)
In your case of twins, the Mishna (Ahilot 7:5) rules that if the dead twin comes out first [and is removed from the house] then the live twin can come out pure [from 7-day impurity; it still is impure from touching the mother who is a Yoledet]. However, if the live twin comes out first then he is impure since (Bartenura) at that point the womb is open to the dead fetus inside or (Rambam) since the dead fetus inevitably follows along immediately.