Successful pregnancies rely on adaptations within the mother1, including marked changes within the immune system2. It has long been known that the thymus, the central lymphoid organ, changes markedly during pregnancy3. However, the molecular basis and importance of this process remain largely obscure. Here we show that the osteoclast differentiation receptor RANK4,5 couples female sex hormones to the rewiring of the thymus during pregnancy. Genetic deletion of Rank (also known as Tnfrsf11a) in thymic epithelial cells results in impaired thymic involution and blunted expansion of natural regulatory T (Treg) cells in pregnant female mice. Sex hormones, in particular progesterone, drive the development of thymic Treg cells through RANK in a manner that depends on AIRE+ medullary thymic epithelial cells. The depletion of Rank in the mouse thymic epithelium results in reduced accumulation of natural Treg cells in the placenta, and an increase in the number of miscarriages. Thymic deletion of Rank also results in impaired accumulation of Treg cells in visceral adipose tissue, and is associated with enlarged adipocyte size, tissue inflammation, enhanced maternal glucose intolerance, fetal macrosomia, and a long-lasting transgenerational alteration in glucose homeostasis, which are all key hallmarks of gestational diabetes. Transplantation of Treg cells rescued fetal loss, maternal glucose intolerance and fetal macrosomia. In human pregnancies, we found that gestational diabetes also correlates with a reduced number of Treg cells in the placenta. Our findings show that RANK promotes the hormone-mediated development of thymic Treg cells during pregnancy, and expand the functional role of maternal Treg cells to the development of gestational diabetes and the transgenerational metabolic rewiring of glucose homeostasis.