Forests are vital for terrestrial ecosystems, providing crucial functions like carbon sequestration and water conservation. In the Yellow River Basin, where 70% of forest coverage is concentrated in the middle reaches encompassing Sichuan, Shaanxi, and Shanxi provinces, there exists significant potential for coal production, with nine planned coal bases. This study centered on Jincheng City, Shanxi Province, a representative coal mining area in the Yellow River Basin, and combined the MSPA analysis method and MCR model to generate the five-period forest ecological network of Jincheng City from 1985 to 2022 under the background of coal mining and calculate the degree centrality, closeness centrality, betweenness centrality, and eigenvector centrality; the correlation between the four centralities and carbon sequestration ability is further explored. Simultaneously, employing the RAND-ESU algorithm for motif identification within forest ecological networks, this study integrates the ecological policies of the research area with the specific conditions of the coal mining region to optimize the forest ecological network in Jincheng City. Findings reveal the following. (1) Forest ecological spatial networks: Forest ecological networks exhibit robust overall ecological connectivity in the study area, with potential ecological corridors spanning the region. However, certain areas with high ecological resistance hinder connectivity between key forest ecological nodes under the background of coal mining. (2) Correlation between topological indices and carbon sequestration ecological services: From 1985 to 2022, the carbon sequestration capacity of Jincheng City’s forest source areas increased year by year, and significant positive correlations were observed between degree centrality, betweenness centrality, eigenvector centrality with carbon sequestration ecological services, indicating a strengthening trend over time. (3) Motif Recognition and Ecological Network Optimization: During the study, four types of motifs were identified in the forest ecological network of Jincheng City based on the number of nodes and their connections using the RAND-ESU network motif algorithm. These motifs are 3a, 4a, 4b, and 4d (where the number represents the number of nodes and the letter represents the connection type). Among these, motifs 3a and 4b play a crucial role. Based on these motifs and practical considerations, network optimization was performed on the existing ecological source areas to enhance the robustness of the forest ecological network.