This is not a bug, this is how automated assignments work. The command module jobs like XO are usually considered to be lower-priority than ship commands, so when a new ship command opens up (from construction, deaths, etc.) it is likely that an officer assigned to a subcommand job like XO will be reassigned to a ship command role.
One common cause here is if you are building a large number of fighters which do NOT have the "No Officers" checkbox ticked in the class design window. Fighters tend to be built frequently and take your low-ranking officers out of subcommand positions so they can command the fighter - I usually don't let officers command fighters because of this (and because having a LCDR in charge of, like, three guys seems a little silly to me).