This is something I've noticed in EB II and other M2TW mods and I guess it is built into the hard-coded game itself (not sure about that, since I haven't played vanilla M2TW for about a decade now). The game simply loves to try and screw over your plans to maintain a consistent patrilineal dynasty. It's something I noticed right away in Stainless Steel, which was easy to avoid if you could marry royal princesses to members of your faction leader's immediate family that held the same surname, to ensure that they had a wife and future offspring. Otherwise the game gets cheeky and tries to marry off any other "family member" who's been adopted or is the offspring of a daughter and an in-law with a different surname. Meanwhile, your core dynastic family dies off without any marriages after a certain number of turns.
In EB II this is a somewhat serious issue since there are trait bonuses involved with maintaining a consistent dynasty of faction leaders and heirs. For instance, the "ethnicity" trait called "PergamonAttalides" for the Pergamon faction. This is essentially the Pergamene royal family, not so much an actual "ethnicity" like the others for that faction (e.g. "Hellen," "Makedon," "Perses", "Mysios", "Lydios", "Xenon", etc.). This trait provides both a piety and an authority bonus.
It is actually quite useful considering how serious bribery and rebellion is in EB II, especially with the new campaign script making things very challenging. Your faction leader needs all the authority bonuses he can get outside of doing the obvious of winning battles and scoring diplomatic deals to increase his prestige (I learned recently that this is another way to increase their authority...carrot and stick approach for your enemies and allied friends). "Piety" is also the equivalent of "influence" in this game, the number of green laurel wreaths a family member has in the status bars. Influence is incredibly important because it is the chief method of spreading your culture to conquered settlements and regions, by placing governors with a great deal of influence there. Increasing your faction's cultural presence (such as "Hellenistic polities" or "Western Mediterranean Polities" or "Urban Tribal States" etc.) ultimately effects public order and the ability to hold onto captured settlements lest they rebel against you.
Essentially, the game is trying to weaken the authority and influence of your faction leaders and their future heirs by toppling the original royal dynasty and producing a line of heirs without this solid trait advantage. This wouldn't be a problem in Stainless Steel, as I mentioned before with the princesses, but in EB II there is nothing you can do about it! You just have to sit there and take it like a good girl, while the game bends you over a barrel and shatters your manhood with devastating pelvic thrusts. Short of cheating and giving your faction leaders a bunch of positive traits, you're basically bound to have mediocre or crappy ones unless you try harder to cultivate them by having them win tons of battles and hoping that they receive good governing traits by building certain buildings in cities where they are placed as governors (which obviously doesn't always work).
So, what can be done about this? Nothing? Is there some sort of mechanic like the princess agent that can ensure your dynasty lasts for a whole campaign? My Attalid dynasty for Pergamon lasted until the 130s BC, which isn't bad considering the game started in 272 BC, but still, it's annoying moving forward (I'm currently at the year 88 BC). Now I have a new dynasty, the "Salaminios" family of Hellens (i.e. native Greeks).