From all we can see about how the stones work there's no reason to believe Tony would've needed to know anything about Gamora. His goal was to destroy Thanos' army, she wasn't part of that army, that's it, end of story.
Just compare with the previous use of the infinity stones:
Thanos eliminates half of (sapient?) life in the universe: This worked, even though obviously Thanos didn't make a list of hundreds trillions of people to eliminate. He didn't need to know anything about who he was going to eliminate, not even that they existed. He wished for it, and it happend.
Banner/Hulk returns the people eliminated by Thanos: This worked, even though obviously Banner/Hulk didn't have a list of everyone Thanos eliminated. He didn't need to know anything about the people he was going to bring back, not even that they existed in the first place – he just wished for it, and it happened. We see that while using the stones he has a clear sense of what exactly his wish is achieving and what not (as he realises that Black Widow can not be returned, which is the bigger problem writing wise albeit needed for plot convenience).
Tony Stark eliminates Thanos's army: This worked, even though obviously Tony Stark didn't personally know everyone in Thanos's enormous army. He just wished for it, and it happened. At the time, Gamora had already defected and thus didn't fall under the set of people Tony Stark wanted to eliminate, so she wasn't. Tony Stark didn't need to know that she defected, was ever part of Thanos's army, or even that she'd ever existed in the first place. He made a wish, and the result he wished for was achieved regardless of his personal knowledge in the moments before using the stones, exactly like it worked every other time the stones were used to achieve something.
As to the mechanism of how this worked, I don't believe there's an explanation in movie canon. Maybe in the instant of using the stones their wielder becomes temporarily omniscient and simply knows every single minute detail that they'd need to know to achieve what they set out to do in addition to being granted the power to do it. Maybe the stones themselves form an omniscient wish-granting collective. I'm not a comic book reader myself, but I expect the comics will have gone into (probably internally contradictory) detail about the mechanics here.
The important point is that regardless of however the stones work mechanically, clearly they are not limited to the personal knowledge of their wielder when it comes to accomplishing whatever they're being used for, because otherwise none of the things we see the stones being used for would've been possible.