Although extensive studies focused on the driver of changing CO2 emission, the roles of labor and capital were largely ignored in shaping spatiotemporal change in CO2 emission and forecasting differences on CO2 emission was few considered, hindering relevant policymaking towards sustainable development in both climate change mitigation and economic growth for developing countries in particular. To fill the gap above, the study explored the roles of capital and labor in contributing to recent CO2 emission in a case of China over 2010–2019 and projecting provincial CO2 emissions to 2030, by proposing two new spatiotemporal logarithmic mean Divisia index models with Cobb-Douglas production function and developing an ensemble forecasting model including machine learning. We found, first, the effects of capital and labor inputs and carbon factor were the positive drivers affecting aggregate CO2 emissions, while the effects of the total-factor productivity and energy intensity were negative drivers. Second, the effects of capital and labor inputs were the negative drivers for narrowing the emission gap. Third, the ensemble forecasting model can improve the generalization ability of CO2 emission predictions. Therefore, we recommend that policymakers focus on optimizing the carbon reduction effects of capital and labor inputs while promoting the development of a circular economy to achieve sustainable economic growth.