It's the same thing with South Korea. The U.S. would likely agree to leave the Korean peninsula in a heartbeat if China agreed to regime change in North Korea, even if it was kept as a buffer state. Geopolitically it would be better for everybody involved. But senior Chinese military leadership feels honor bound as the protector of the North Korean regime, which also stands as living evidence of Chinese military superiority over the U.S. And so China defends the most egregious behaviors of North Korea, even when they openly defy China on the international stage, and even when North Korean policies cause domestic trouble in China.
A comparable mentality in the U.S. might be that regarding Cuba--completely and utterly irrational, driven by an antiquated historical narrative and unjustifiable sentiments. In some respects an even better example might be Israel, but it's exactly because it's an apt comparison that I can't actually make it--there's little room for nuance and too little good faith allowance in the domestic discourse.