Watchtower does read when you "gain" a card you may put it on top of your deck so buying a card then immediately returning it may take precedence, although its arguable.
Well, "immediately" is a meaningless term in Dominion. It occurs to me though that you're at least half right: as written this is an on-buy effect, so the "return" happens between the "buy" and the "gain". Which means ultimately this card text doesn't actually do anything: You buy the card, then return the card (no effect since it's still on the supply pile), then gain the card anyway as an effect of buying it. So really the timing of this effect needs to be on-gain rather than on-buy, with a stipulation that it only applies to cards that have been bought. "
When you gain a card by buying it, return it to the supply." Ta-da!
When you have a Royal Seal in play, the two on-gain effects are simultaneous, so you can choose whether to put the card on your deck first or return it first. Now we wade off into the weeds because we need Donald's "lose track" rule from an arcane BGG thread, and the rule hasn't been finalized to account for cases like this*. But regardless of your interpretation, you can ultimately choose to put the card on top of your deck or back on the pile by choosing the order of the two effects and possibly choosing not to use Royal Seal's power.
Hehe, rules lawyering over silly bad-idea card effects is fun
*Currently the only real-game effects of the "lose track" rule center around Throning or Kinging a Mining Village. Grossly simplified, TR and KC can't move Mining Village back from the trash to the play area because they can't find it there, and a TR'd or KC'd Mining Village can't trash itself more than once because it can't find itself in the trash. Possession adds a slight wrinkle, but the effect is the same: none of these cards can find a Mining Village in Possession's fake trash pile either.