Crop diversification is pivotal in sustainable agriculture, influencing soil microbial communities and soil nutrient cycling functions. Yet, the impacts of incorporating medicinal plants into crop diversification strategies on the functional characteristics of these microbial communities remain understudied. This research elucidates the benefits of diversified cropping systems by assessing soil nutrient content, diversity and composition of soil microorganisms, the abundance of functional genes involved in carbon (C), nitrogen (N) and phosphorus (P) cycling, and overall agricultural productivity; collectively referred to as ecological benefits. The experimental design included four treatment groups: (1) continuous maize (Zea mays L.) cultivation (MC); (2) maize–A. lancea (Atractylodes lancea Thunb.) intercropping (MA); (3) maize–sorghum (Sorghum bicolor L.) rotation (MS); and (4) maize–A. lancea intercropping combined with sorghum rotation (MSA). Findings indicate that diversified cropping treatments significantly enhance the alpha diversity of soil bacterial communities over fungal communities. NH4+ and NO3− predominantly influence the composition of soil bacterial communities, with a notable increase in the relative abundance of Acidobacteriota, Gemmatimonadota, and Chloroflexi. Compared to MC treatment, the MA and MSA treatments significantly increased the abundance of C (121.44%, 294.26%), N (206.57%, 294.26%), and P (112.02%, 225.84%) cycling genes. The inverse variance weighting evaluation demonstrates that, compared to the MC treatment, the MS (5.34) and MSA (8.15) treatments significantly boost soil ecological benefits. Overall, diversifying the cultivation of A. lancea with grains can enhance the ecological benefits of the soil. This study offers new perspectives on diversified planting, particularly in terms of species selection and practical combinations on farmland.