High levels of alkali and alkaline earth metals (AAEM, including K, Na, Ca, and Mg) in sludge needs to be removed in pretreatment process for alleviating adverse effects on subsequent disposal. Theoretically, the liquid environment provided by the pretreatment technology of thermal hydrolysis (TH) is the ideal condition for the dissolution of AAEM. Therefore, this work quantified AAEM removal efficiency of TH and carbonaceous skeleton (CSkel) assisted TH that we previously proposed for sludge dewatering. Then the mechanism of AAEM dissociating from sludge was explored through the new perspective of biological structure evolution and chemical species transformation. The results showed that all of the AAEM in raw sludge was trapped in extracellular polymer substances (EPS) and cells. Only the water-soluble K/Na in EPS could be released by TH to the supernatant, the residual K/Na in EPS was organically linked with humic matters that were generated through the degradation of proteins. Water/NH4Ac-soluble K/Na in cells still stayed inside with a more stable form of HCl-soluble after TH. Fortunately, with the assistance of CSkel, this part of K/Na could be leached out due to organic acids derived from hemicellulose decomposition. In such a case, the removal efficiency of K/Na was elevated to 55.5% and 72.5%, respectively. Unlike K/Na, nearly all the Ca/Mg in EPS were transferred to cell residuals during TH. They were combined with the bio-phosphorus in cell residuals as the form of HCl-soluble Ca/Mg-P precipitates, rather than carbonates, sulfates or other compounds. This precipitation reaction was also moderately suppressed in CSkel-assisted TH with low pH, then 7.7% and 34.1% of Ca/Mg were taken away by filtrate. This means that appropriately raising the reaction temperature and adding CSkel with high hemicellulose/cellulose contents can promote the removal of AAEM in sludge during TH process.