Why does a fetus drink and urinate into the amniotic fluid?
In utero, the growing little human is getting ready to be an independently functioning individual. While it is everything but that, it must be able to obtain fluids and nutrients through its mother's milk, and that from pretty much the first hour of its life.

To develop proper kidney function, the growing fetus needs to ingest fluids just as it will do post partum. Because a mini bar isn't available, it has to drink whatever is available, i.e., amniotic fluid and indeed, its own urine. Shortly after the kidneys start to produce urine, the fetal swallowing commences. 

Amniotic fluid is 98% water and 2% salts and cells from the baby. Until the fetal kidneys start working during month four, amniotic fluid is made by the mother’s body. But after month 4, the fetus starts to make his contribution to the amniotic fluid by urinating into it (Penn Medicine). Production of amniotic fluid is then predominately accomplished by excretion of fetal urine (300 ml/kg fetal weight/day or 600 to 1200 ml/day near term) and the secretion of oral, nasal, tracheal, and pulmonary fluids (60 to 100 ml/kg fetal weight/day). Fetal breathing movements also contribute by efflux of lung fluid into the amniotic fluid. Removal of AF is predominately accomplished by fetal swallowing (200 to 250 ml/kg fetal weight/day) (Underwood et al., 2005). 

The water in amniotic fluid originally comes from maternal plasma and passes through the fetal membranes. As the placenta develops, water and solutes from maternal plasma pass across the placenta to the fetus and then to the amniotic fluid (Underwood et al., 2005), see Fig. 1. 

Swallowing its own urine is not only not dangerous, it is essential to proper development. A decrease in fetal urine production or excretion can result in a reduced amount of amniotic fluid (oligohydramnios). Oligohydramnios can result in fetal lung deformations (pulmonary hypoplasia) and increased risk of infection.  Fetal mortality rates as high as 80-90% have been reported with oligohydramnios diagnosed in the second trimester (Source: Patient Info). 

If the fetus would have to prevent the production of urine in utero, the kidneys would have to remain nonfunctional during development, which would be disastrous once it is born. Renal failure is in fact pretty common in newborns, but can be fatal without proper treatment (Andreoli, 2004).


Fig. 1. After month 4, amniotic fluid is derived from maternal plasma that passes via the placenta, to the fetus and then to the amnionic fluid. Source: Underwood et al., (2005). 

References
- Andreoli, Semin Perinatol (2004); 28(2): 112-23)
- Underwood et al., J Perinatol (2005); 25: 341–48