Hydrothermal carbonization (HTC) is an efficient method for converting biomass into biochar. Hydrochar contains catalytic components such as alkali and alkaline earth metals (AAEMs); however, the mechanisms by which highly active metals such as potassium (K) and sodium (Na) catalyze the conversion of small carbon–water compounds into hydrochar in hydrothermal environments remain unclear. In this study, glucose was used as a small molecule model, and Na+ and K+ were used as catalysts to investigate the catalytic reaction mechanism during the hydrothermal process using density functional theory (DFT). In the presence of different ions at various binding sites, glucose isomerizes into fructose, which subsequently undergoes three consecutive dehydration reactions to form 5-hydroxymethylfurfural (HMF). The results indicate that the catalytic effectiveness of Na+ and K+ in the isomerization of glucose to fructose is optimal when interacting with specific oxygen sites on glucose. For Na+, the interaction with the O1 and O2 oxygens provides the lowest reaction barrier of 37.16 kcal/mol. For K+, the most effective interactions are with the O3 and O4 oxygens and the O5 and O6 oxygens, resulting in reduced reaction barriers of 54.35 and 31.50 kcal/mol, respectively. Dehydration of fructose to HMF catalyzed by Na+ ions, the catalytic effectiveness at different positions is ranked as O5O6 > O1O5, whereas for K+, the ranking is O1O5 > O5O6. This study explores the catalytic effects of Na+ and K+ at different binding sites on the hydrothermal reactions of glucose at the atomic level, offering theoretical support for designing catalysts for the HTC of sludge.