A plethora of studies have investigated the nonlinear correlation between the built environment and metro ridership. However, the spatiotemporal heterogeneity of this relationship from the perspective of ridership segmentation has received little attention. To address this gap, this study capitalizes on data collected from Wuhan, China. We employ a sophisticated amalgamation of quantile regression models and machine learning methods to construct direct ridership models (DRMs) for different ridership segments (low, medium, and high) and distinct temporal intervals (weekdays and weekends). The primary objective of these models is to scrutinize the salient factors that influence metro ridership within the context of spatiotemporal heterogeneity, including nonlinear relationships and threshold effects of the built environment. The research findings reveal pronounced differences in the significant influencing factors of the built environment on metro ridership across various ridership segments and temporal periods. Additionally, conspicuous spatiotemporal heterogeneity is discerned in the nonlinear relationships and threshold effects between the two. Consequently, considering the spatiotemporal heterogeneity inherent in metro stations, targeted policy optimization measures fostering the sustainable development of transit-oriented development (TOD) strategies are essential.