Transportation and built environment significantly influence urban air quality, yet their joint mechanisms remain unclear due to complex nonlinear relationships such as bidirectional causality and self-selection. This paper proposes a dual-layer analytical framework to investigate the impact mechanisms of transportation and built environment on urban air quality. First, a ”Dual-XGBOOST–SHAP” framework is employed to analyze feature influence mechanisms. Then, η² permutation tests and Mantel tests are applied to explore the spatial heterogeneity and driving factors of these influence mechanisms. Results show that vehicle emissions and industrial proportion are the primary drivers among transportation and built environment features, respectively. Furthermore, the influence mechanisms exhibit significant spatial heterogeneity, which can be categorized into spatial gradient type and discrete difference type based on whether they are geographically driven. These findings provide policy guidance for future urban air quality management.