It’s a feature disguised as a bug, and was originally done on purpose by @Nimhain after complaints of resorting after every troop upgrade.
Search criteria is evaluated once, when you first use the troop menu. It does not update again until you restart game. It should update each time you open troop menu.
Example because I know it sounds confusing.
Sort by rarity, and ascend a troop from legendary to mythic. Close and reopen troop menu and sort again, the troop shows up in the legendary group.