According the Oxford English Dictionary, if you “turn the tables” on someone, it is generally understood that you have reversed the fortunes in your favor to some capacity, so as to “reverse one’s position relative to someone else, especially by turning a position of disadvantage into one of advantage.” Useful saying, especially for motivational halftime speeches at sporting events, but where does it come from?
Believe it or not, from board games!
Backgammon and similar games belong to a class of board games referred to as “tables,” a general name given to games played on a board with dice. If the game wasn’t going in your favor, you would have to “turn” them, figuratively, if you wanted to win. You can’t actually “turn the tables” in a game of backgammon, although that would be nice. The phrase is a metaphor, a substitute for the common idea of a “comeback,” because you would have to reverse the board/the players’ current positions/situations in order to change the outcome.
While not as directly relevant to the meaning of the phrase in today’s language, there’s also a hint of this phrase, at least in terms of the words themselves, found amongst old-school dinner party procedures. To prevent anyone from being excluded from conversation, the host would choose a direction (typically the right) and speak with the person to that side of him/her. Everyone else was to follow suit, until the host “turned the tables” halfway through the meal, at which point everyone then switched their focus to the person on the opposite side.