What I’ve heard: the nukes are about internal stability as well as defense. If someone wants to overthrow the Kims they want china to have to be worried about a civil war there, so they will support the current rulers government (more than they already do). An unpredictable nuclear armed state on your border is scary.