The rising global health crisis of childhood overweight and obesity is potentially influenced by caesarean delivery (CD), but it remains a subject of ongoing debate. The gut microbiome, which is affected by delivery mode and can impact body weight, might play a role in this issue. However, the complex relationship between them remains poorly understood. We analysed data from a randomised, double-blind, placebo-controlled trial VDAART cohort, including BMI percentiles from 683 children aged 2–8 years and 1672 stool samples collected between 3 months and 5 years (all data in this study were collected between May 2010 and February 2018). To evaluate how CD relates to BMI trajectories, we conducted permutation testing and discussed the effect of confounding factors. We then used PERMANOVA, random forest classification, and Generalised Microbe Phenotype Triangulation (GMPT) to explore the role of the gut microbiota in mediating this relationship. Compared with vaginal delivery, intrapartum CD (iCD) rather than antepartum CD (aCD) was associated with a higher BMI percentile trajectory (Δ = 31.8%; 95% CI, 16.25%–47.55%; P = 0.001, Permutation test), and this was observed only among female children. Moreover, delivery mode was significantly associated with early-life gut microbiota, with effects also limited to females (F = 2.15 and 2.47 at months 3–6 and at age 1; P = 0.035 and 0.007, PERMANOVA). Random Forest models using early microbiota data can predict later overweight/obesity, performing best among iCD-born females (AUROC = 0.88; 95% CI, 0.83–0.94 for age 2), indicating an optimal intervention window before age one. Finally, GMPT identified 24 early-life taxa potentially mediating iCD-related overweight/obesity risk (11 preventive; 13 permissive), including Bacteroides ovatus, Bifidobacterium bifidum, Clostridium leptum, Eggerthella lenta, etc. Our results indicate that CD types and children’s sex are key factors in this interaction, offering a possible explanation for the ongoing debate about whether CD is linked to childhood overweight/obesity, and providing valuable insights for future intervention strategies.