Because Data was of a lower rank!
Data was a Lieutenant Commander and Troi was promoted to Commander. Simply put, the ranking of Commander outranks Lieutenant Commander. Data was speaking technically that Troi outranked him - because Troi was a Commander, a higher rank, she could give him an order.
You are getting confused with the chain of command on the ship - Data was third in command (second officer) as pointed out in the question. What this means is that should both Picard and Riker be unavailable, Data is next in line to take command of the ship and becomes an 'acting' Captain, which would then outrank Troi.
The important point to take away from this answer is that there is a difference between chain of command 'rank' and actual 'rank'
The chain of command refers to the order when the captain is absent of who will assume the captain's role. On the Enterprise-D this goes:
So, if Picard and Riker are absent, Data essentially assumes the role of Captain.
In terms of real rank though, on the Enterprise-D we have
- Commander (this is where Troi sits)
- Lt Commander (this is where Data sits)
So, when Data assumes the captain's role, he jumps to position 1 on the chain of command and therefore also on the ranking. I hope this makes sense!