Agricultural activities and rapid urbanization have significantly impacted groundwater quality, especially in semi-arid and arid regions. This study comprehensively evaluated the quality of phreatic and confined groundwater in the Yinchuan area, China, using long-term monitoring data from 1991 to 2018. Geospatial analysis model was employed to explore the spatiotemporal evolution of groundwater hydrochemistry. The effects of land use changes on groundwater quality were assessed using correlation analysis and a multiple linear regression model (MLR). The findings indicate significant temporal variations in groundwater quality, with phreatic water consistently exhibiting high salinity and hardness. The groundwater quality indices for phreatic water were frequently more polluted than confined water. From 1991 to 2018, the hydrochemical composition of phreatic water evolved from HCO3-Mg and HCO3•SO4-Mg to more complex forms such as HCO3•SO4•Cl-Mg and HCO3•Cl-Mg. In contrast, confined water predominantly maintained its HCO3-Mg type and HCO3•Cl-Na (Na•Mg) type water. Urban land had rapidly expanded in the past three decades, increasing by 318.75% compared to 1991. The water body and urban area diminished the quality of phreatic water. High salt water in increase of TDS, Cl–, SO42–, Mn, TH, NO3–, F–, and Fe into phreatic water. NO3–, NH4+, and F− in phreatic water could be impacted by human and industrial activity in urban areas. This study provides valuable insights for local decision-makers to effectively manage groundwater resources and solve issues of groundwater scarcity and water quality problems in arid and semi-arid locations.