At present, the mechanism of CO and CO2 production in coal spontaneous combustion is controversial. With the hope of exploring the generation mechanism of CO and CO2 in the low-temperature oxidation of coal, in this study, the correlation between the relative contents of three active functional groups, –CH3/–CH2, -C = O, and –COOH and the generation law of CO and CO2 in the low-temperature oxidation of coal samples with different metamorphic degrees was explored by means of principal component analysis, Pearson linear analysis, and Fourier transform infrared spectroscopy. The results indicate that –CH3/–CH2, -C = O, and –COOH in low-rank lignite (HC) are significantly correlated with the concentrations of CO and CO2. The -C = O and –COOH in medium-rank bituminous coal (BC) are closely correlated with the concentrations of CO and CO2. The concentrations of CO and CO2 in high-rank anthracite (CQ) show the highest correlation with the relative content of –CH3/–CH2, followed by their correlation with the relative content of -C = O, and their correlation with the relative content of –COOH is relatively low. Thus, it can be concluded that the generation mechanism of CO and CO2 varies with the metamorphic degrees of coal in coal spontaneous combustion. CO and CO2 generated from low-rank HC mainly come from continuous generation and oxidation of inherent and secondary alkyl chains and those generated from medium-rank BC mainly come from the oxidation of oxygen-containing functional groups. Besides, for high-rank CQ, CO is mainly generated from the process in which alkyl chains in coal oxidize to form carbonyl groups which then break to form CO, and a small part of CO comes from the coal-oxygen free radical reaction. As for CO2, its sources are more complex. A big portion of CO2 comes from the free radical reaction and CO2 may also come from the direct conversion of CO at high temperature and in the presence of water. Finally, the reaction mechanism of C = O· and ·OH free radicals was studied by quantum chemical calculation. The calculation results reveal that the free radical reaction can occur spontaneously and release a certain amount of heat under certain conditions, thus playing a positive role in promoting coal spontaneous combustion.