I know the meaning of the phrase, but where exactly does it come from?
Etymonline to the rescue:
Figurative phrase turn the tables (1630s) is from backgammon (in O.E. and M.E. the game was called tables).
In a comment, thesunneversets wrote:
I found this online, which clarifies even further: Games like backgammon are known as 'tables' games. The phrase 'turn the tables' derives from these games and from the practise of reversing the board so that players play from their opponent's previous position.
The first known example of the figurative use of the phrase in print is in Robert Sanderson's XII sermons, 1634:
"Whosoever thou art that dost another wrong, do but turn the tables: imagine thy neighbour were now playing thy game, and thou his."
Jesus turned the tables over (John chapter 2), and in doing so, was probably making a rather strong point that Jewish elements such as the temple were being given new meaning and/or being replaced in His system. It would seem that this incident probably led, at least in part, to the English phrase.