Zecharia 3:4-5
ד. וַיַּעַן וַיֹּאמֶר אֶל הָעֹמְדִים לְפָנָיו לֵאמֹר הָסִירוּ הַבְּגָדִים הַצֹּאִים מֵעָלָיו וַיֹּאמֶר אֵלָיו רְאֵה הֶעֱבַרְתִּי מֵעָלֶיךָ עֲוֹנֶךָ וְהַלְבֵּשׁ אֹתְךָ מַחֲלָצוֹת ה. וָאֹמַר יָשִׂימוּ צָנִיף טָהוֹר עַל רֹאשׁוֹ וַיָּשִׂימוּ הַצָּנִיף הַטָּהוֹר עַל רֹאשׁוֹ וַיַּלְבִּשֻׁהוּ בְּגָדִים וּמַלְאַךְ יְהֹוָה עֹמֵד
. “And he [the angel] raised his voice and said to those standing before him, saying, ‘Take the filthy garments off him.’ And he said to him, ’See, I have removed your iniquity from you, and I have clad you with clean garments.’” “And I said, ’Let them put a pure miter on his head,’ and they put the pure miter on his head. And they had clothed him with garments while the angel of the Lord was standing.”
Zecharia is shown a vision of Yehoshua the Kohen Gadol wearing dirty clothes, which subsequently the Malach Hashem commands to be removed from him. It is clear from passuk 4 that these dirty clothes represent sin, as immediately upon removing the garments, Yehoshua is told that his sin has been eradicated.
The Gemara in Sanhedrin 93a explains that his iniquity hinted at in these pesukim was that his sons did not marry women appropriate for the Kehuna (priesthood) and he failed to rebuke them. The commentators on this passuk explain that these women were in fact not Jewish, based on Ezra 10:18 which says "And it was found that from the sons of the Kohanim who had married foreign women, the sons of Yehoshua..."
Interestingly, Yehoshua's sin was not due to his own wrongdoing, but rather a result of his sons' iniquity and his failure to reprimand them (Rashi 3:3).
The importance of rebuking someone has it is source in parshas Kedoshim (Vayikra 19:17) where the Torah tells us “You shall not hate your brother in your heart. You shall surely rebuke your fellow, but you shall not bear a sin on his account.” Targum Onkelos explains this last phrase to mean that if a person fails to rebuke his fellow, he bears his punishment. This can be understood better through the concept of "kol yisrael areivim zeh bazeh" (Shevuos 39a). The Kli Yakar quotes the famous parable of a passenger on a ship who decided to bore a hole in the floor of his room, allowing water to enter. When the other passengers furiously berated him for causing the whole ship to sink, the man brazenly replied that he had paid for his room and so had the right to do as he pleased. This is the principle of “kol yisrael areivim zeh bazeh” where one person's actions affect the whole of Klal Yisrael.
However, the kli Yakar points out that if one tried his utmost to rebuke someone who subsequently failed to listen, the one who offered the rebuke is not held responsible for the person’s subsequent transgressions.
Another understanding of the passuk above is that it is essential that one reprimand another in a careful, sensitive manner so as not to embarrass the person. The passuk is cautioning that although you shall surely rebuke your friend, make sure that with your rebuke, you do not incur a sin (of embarrassing him).