This study assesses seasonal and spatial variations in soil quality across four agroecological zones (Badagry, Epe, Ikorodu, and Ojo) in Lagos State, Nigeria, using physico-chemical soil properties and machine learning techniques. Samples of soil were gathered in both the rainy and dry seasons at 0–15 cm and 15.1–30 cm depths, were analyzed for physico-chemical parameters, including pH, electrical conductivity (EC), organic carbon (OC), nitrogen (N), cation exchange capacity (CEC), and base saturation (BS). The Soil Quality Index (SQI) was computed employing a weighted scoring method based on fertility indicators. EC was higher in the rainy season, while pH decreased, indicating leaching effects. Organic matter and nutrient levels showed moderate seasonal and depth-related variations, with Ojo exhibiting the highest OC content. A t-test found no significant difference in SQI between seasons (t = 0.76, p = 0.448), suggesting temporal stability in soil quality. Among machine learning models, Random Forest achieved the highest predictive accuracy for SQI (R² = 0.94, MSE = 0.0003), outperforming Partial Least Squares Regression and Cubist models. Cross-validation (Root Mean Square Error (RMSE) = 0.015–0.017) supported targeted soil management strategies, identifying Ojo as a high-fertility zone (mean SQI = 0.45). These findings highlight the efficacy of integrating machine learning approaches for soil quality assessment, offering insightful information on soil management and sustainable agricultural engagement in Lagos State’s diverse agroecological zone.