Pre-DADT repeal, any season 1 really.
Lorne and Sheppard are overheard by a member of the Atlantis group who wants to get rid of Sheppard. However, he/she doesn't know who it was that Sheppard was with. Not wanting Lorne to be removed from Atlantis as well, Sheppard convinces McKay to go along with being his fake boyfriend somehow. Lorne's not exactly happy with that plan, but he is thankful.
Eventually, McKay and Lorne are left on Atlantis, while Sheppard gets sent back until he can figure out how to get back to Atlantis.