The fetus pees and poops in its amniotic fluid however its waste is sterile because its not exposed to bacteria in the environment. Fetus's normally don't carry solid waste in their amniotic fluid because their waste isn't made up like an adults, its made up of dead cells being removed from the body which looks like a tar like substance that's not full of harmful bacteria.
When the mother breaks before delivery , the staff check to see if it has stool in it. If it does they need to suction the baby right away to keep it out of the babies lungs. When the baby is inside of the womb, stool cannot enter the lungs but as soon as the baby emerges and takes its first breath... it can inhale waste which can cause respiratory problems