We've got a saying in Spain:
ir por lana, volver trasquilado
I've found that in English already exists a similar proverb:
Many go out for wool and come home shorn
many who seek to better themselves or make themselves rich, end by losing what they already have.
But I'm not certain that the two of them share the following nuance. In Spanish it's applied also to
Alude a quien fue a ofender y volvió ofendido
Let me adapt and translate
The one who try to offend you, ends offending himself.
Offend, meaning in this case, that someone tries to demonstrate that you are wrong or that you are stupid but at the end he stands corrected or definitively showing that he is the stupid one.
Another saying in Spanish that reflects this meaning is
Le salió el tiro por la culata / His gun backfired
Is correct the use of Many go out for wool and come home shorn in this case? Are there any other idioms for this case?