The creature returns to the opponent when the "until end of turn" effect wears off during the cleanup step. It taps during the Cleanup step (if it is not already tapped), so any abilities triggered off it tapping happen at that time.

10/1/2008

You tap the creature when you lose control of it for any reason -- because Ray of Command's effect ends, or because a spell or ability causes another player to gain control of it.