Data is a line officer, Troi is a staff officer. Troi is part of the medical staff. Just because she's certified to command doesn't mean she's part of the chain of command. Data is
part of the chain as second officer (CO Picard, XO Riker, then Data), and
he has more experience in command.
Rank and position are two different concepts. Troi had the rank, but not the position.