What is the idiom/phrase for doing something to someone and the same thing will also happen to you?
Solution 1:
What goes around comes around idiom
used to say that if someone treats other people badly he or she will eventually be treated badly by someone else. (M-W)
Solution 2:
Those who live by the sword die by the sword.
My favourite Source; Matthew 26:52
BibleHub gives many variants. An example of this version appears in the Guardian {Simon Weil}.