Any time I imprison my non-heir son he automatically becomes heir. Why is that? For example, I uncover a plot by my second son to assassinate me or my heir and after I decide to imprison him (the legal way with no penalties) he goes to jail but also becomes my heir. It is extremely annoying because I don't want to keep executing half my family just to keep my preferred son as heir.
I'm playing as the Duke of Galich. I switched from Gavelkind as soon as I could, so the succession laws are Agnatic-Cognatic Primogeniture.