There are two explanations for the origin of this expression that means to pay someone back in their own coin, or give them a taste of their own medicine. 

The first explanation refers to the law of retaliation, which appeared in the Code of Hammurabi, the King of Babylon, circa 1730 BC. This law advocated individual revenge by subjecting the offender to the same pain that he caused. “Rendre la monnaie de sa pièce” meant definitively giving back exactly what is due.   

Another explanation came from the navy during the era of warships and naval battles. Back when navy ships all had sails, the navy sailors would put a small coin-sized effigy of the king into their gunpowder, so when the bullet hit the enemy ship, the “piece” was returned and vengeance was achieved.