If you always make fun of people who wear glasses and then it turns out that you need glasses too and you get made fun of, this is an example of getting your comeuppance.
Origin of comeuppance; from come + up + -ance
A comeuppance is invariably a bad experience. Even so, some dictionaries leave open the possibility of a positive outcome, either explicitly in the definition or by using synonyms such as just deserts, which can be positive.
From come up (“appear before a judge”) + -ance.