It's been reported literally hundreds of times by now, in top-level posts here or in the Bug Reports sub-forum, and in discussion threads aimed at the devs (mostly dev diaries and feedback threads).
The really stupid thing is that it's quite simple, and obvious enough in cause that I was able to "reverse engineer" it without looking at the game code at all (just at the game files). It's also trivial to fix.
THE CAUSE: The problem is observed when a ruler without a "pre_ruler_class" loses re-election (incidentally, this happens for Oligarchies too). However, the actual bug arguably occurs earlier, at game creation, when the game spawns starting rulers of various empires with no "pre_ruler_class" designation. You can see each ruler, including whether they have a pre_ruler_class, by looking at the decompressed savegame file.
Specifically, that happens when an empire type is able to have multiple leader classes become rulers. There are some empire types where only Governors can be elected, and at least one (Technocracies) where only Scientists can be elected; in those empire types the starting ruler will have a pre_ruler_class set to the correct type. However, there are also many empire types that either have no restriction, or allow some but not all types (anything martial allows both Admirals and Generals, for example). In those empire types, the starting ruler will have no pre_ruler_class, and will thus vanish into the void upon losing re-election.
THE FIX: There are two easy ways to fix this. One of them is to, when creating a ruler from nothing (at game start, or possibly any other time an empire is created), always assign them a pre_ruler_class randomly chosen from among the allowed classes. The other one is, whenever a ruler without pre_ruler_class loses re-election, randomly convert them to an eligible class. The first is the better fix but the second is arguably simpler. One could of course do both, a belt-and-suspenders type approach (ensure that the situation doesn't come up *AND* that you can handle it if it does).
You can manually fix the problem by, before an election occurs, saving the game, unzipping the save, editing the game state to ensure every ruler has a pre_ruler_class, and re-zipping the save with the edited file. The instructions for save-game editing are on the wiki.