The commentaries struggle to understand the seemingly cruel hoax to which Yosef subjected his brothers, when he concealed from them his true identity, accused them of espionage, incarcerated Shimon, and finally planted his cup in Binyamin’s sack to incriminate him for a theft that he did not commit.
Yosef became known throughout the generations as “Yosef HaTzaddik,” implying that he was perfectly righteous in all matters, both bein adam l’makom (between man and God) and bein adam l’chaveiro (between man and his fellow). How could a tzaddik submit his brothers to such terrible suffering? And why did he show no mercy to his aged father, overwrought with grief and fear for fate of his sons, as the Torah so poignantly relates:
ויאמר אלהם יעקב אביהם "אתי שכלתם יוסף איננו ושמעון איננו ואת בנימן תקחו עלי היו כלנה." ויאמר ראובן אל אביו לאמר "את שני בני תמית אם לא אביאנו אליך תנה אתו על ידי ואני אשיבנו אליך." ויאמר "לא ירד בני עמכם כי אחיו מת והוא לבדו נשאר וקראהו אסון בדרך אשר תלכו בה והורדתם את שיבתי ביגון שאולה."
Their father Yaakov said to them, “You have bereaved me! Yosef is gone, Shimon is gone, and you would take Binyamin. All this has befallen me.”
Then Reuven said to his father, “You may kill my two sins if I do not bring (Binyamin) back to you. Place him in my hands and I will return him to you.”
“My son shall not descend with you,” he said, “for his brother has died, and he alone remains. If an accident befalls him on the path you walk, you will bring my old age down into the grave in misery.”
For the twenty-two years that Yosef was separated from his father, he must have realized Yaakov’s anguish in imagining him to be dead. Common decency should have required him to inform his father of his wellbeing, as soon as he was freed from prison. Why then did he conceal his identity until the very last moment?
According to the Ramban, Yosef realized that his dreams of his family bowing down to him were a prophetic vision. To bring about the fulfillment of this prophecy, he had no choice but to conceal his identity, despite the regrettable pain that this would cause Yaakov and his sons. 
The Akeidas Yitzchak adds that Yosef had to place his brothers in a situation where they would be forced to stand in Binyamin’s defense, and thereby atone for their sins against Yosef. 
Based on these insights, we can follow the development of Yosef’s plan step by step. The sin of the brothers in kidnapping Yosef and selling him as a slave was not so much the act of violence itself, which perhaps could have been justified by any one of the reasons offered by the commentaries. Rather, even after all the justifications, the accusation of their utter mercilessness hovered over their heads, as they themselves confessed:
ויאמרו איש אל אחיו "אבל אשמים אנחנו על אחינו אשר ראינו צרת נפשו בהתחננו אלינו ולא שמענו על כן באה אלינו הצרה הזאת."
The brothers said to one another, “We are guilty of (harming) our brother, since we saw the plight of his soul when he pleaded with us but we ignored him. Therefore this misfortune has befallen us.”
Where was the compassion that every sensitive person should naturally feel towards his own flesh and blood? Where was the brotherly love that is the foundation of our entire Torah? How could they have ignored his desperate cries for mercy, while they sat down to eat bread? This was their inexcusable sin, which Yosef felt obligated at all costs to expunge, for the benefit of all future generations of Klal Yisrael.
The early Poskim discuss the concept of “teshuvas hamishkal –repentance to counterbalance the sin”, which involves a certain degree of suffering that a person must endure to cleanse himself of the enjoyment he received from sin. In this case, the brothers had to suffer for the sake of Binyamin, who took Yosef’s place as Yaakov’s favorite, in order to cleanse themselves of the benefit they received by harming Yosef.
Yosef first demanded of them, ואת אחיכם הקטן תביאו אלי - “Bring me your youngest brother,” striking their hearts with the first pangs of fear for Binyamin’s welfare, while meanwhile awakening their feelings of love and brotherhood for him. It was then that they first said, אבל אשמים אנחנו על אחינו - “We are guilty of harming our brother.” They had begun to recognize the atrocity of their sin in sundering the bonds of brotherhood by selling Yosef as a slave.
By admitting their mistake, they had taken the first step in their path towards teshuvah. Their second step was taken when they offered themselves together in slavery to pay for the theft of the cup, וגם אנחנו נהיה לאדני לעבדים - “We shall also be slaves to our master.” By resolving to face their difficulties as a group, they had reached the admirable recognition that all Jews are truly responsible for one another.
The completion of their teshuvah was finally attained when Yehuda declared his willingness to become Yosef’s slave in place of Binyamin. The highest expression of love for another human being is when one is willing to accept suffering in his place, as we find expressed in the Mishna, “Rebbe Yishmael said: Let me be the atonement for Bnei Yisrael.” Rav Ovadiah Bartenura explains that in Rebbe Yishmael’s great love for the Jewish people, he prayed that any misfortune intended for Bnei Yisrael should befall him instead.
Only after Yosef saw that his plan had come to fruition and the solid foundations of brotherly love had indeed been laid in Klal Yisrael, was he at last able to reveal himself and express to them the great love that he felt towards them:
ויאמר יוסף אל אחיו גשו נא אלי ויגשו ויאמר אני יוסף אחיכם אשר מכרתם אתי מצרימה ... והנה עיניכם ראות ועיני אחי בנימין כי פי המדבר אליכם.
And Yosef said to his brothers, “Please come to me.” They came close and he said, “I am Yosef your brother, whom you sold to Egypt … Your eyes can see, and the eyes of my brother Binyamin, that it is my mouth that speaks to you.”
Rashi explains that after Yosef revealed his identity, he saw his brothers shrink backwards in dismay. He sympathized with their shame and soothed their hearts with warm words and gentle supplications to draw close to him in brotherhood. He assured them that just as he had no grievances against Binyamin, who took no part in their crime, he had no grievance against them either. Their sin against him had been atoned and the bonds of brotherhood were fully restored.
May we also merit to mend the rifts in our families and communities, drawing together in love and brotherhood, and so merit the fulfillment of Moshe Rabbeinu’s prophecy:
ויהי בישרון מלך בהתאסף ראשי עם יחד שבטי ישראל.
He shall be King in Yeshurun, when the heads of the nation gather together, and the Tribes of Israel are united.
Hashem’s Kingship will be revealed upon us when at long last we unite together in peace and brotherhood.
 Sotah 13b, Rashi s.v. Kiyeim ze mah she’kasuv b’zeh
 Bereishis 42:36-38
 Ramban’s commentary on Bereishis 42:9
 Akeidas Yitzchak: Sha’ar 30. See also Abarbanel.
 See commentaries on Bereishis 37:18, Seforno, Ohr HaChaim, et. al.
 Bereishis 42:21
 See Orchos Tzaddikim: Shaar HeTeshuvah
 Bereishis 42:20
 Bereishis 44:9
 Shavuos 39a
 Negaim 2:1
 Bereishis 42: 4,12
 Devarim 33:5