In the context of diverse urban building density, creating pedestrian-friendly cities is crucial for sustainable development. However, previous studies have revealed potential variations in the influence of building density on walking and in the associations between built environment factors and walking across different building densities. The reasons behind these variations have not been thoroughly investigated. Pedestrian volume on the street is one of the main indicators of walking. Therefore, this study applied the RF + PDP model to explore the nonlinear relationship between building density and pedestrian volume and the interaction effect of building density on the relationship between built environment factors and pedestrian volume. Empirical analysis conducted in Chengdu City revealed the following: (1) Building density influenced pedestrian volume in a nonlinear manner, and the pedestrian volume reached the peak when the building density was at 0.3. (2) There existed interaction effects of building densities and built environment factors on pedestrian volume. (3) The impacts of mesoscale built environment factors (such as distance to transit) and microscale built environment factors (including vegetation index, road index, and sidewalk index) on pedestrian volume were strongly modulated by building density. These findings have important implications for developing targeted planning policies aimed at creating pedestrian-friendly cities.