We know that Yosef was a Tzaddik. Why then did he deceive his brothers into believing that he was a stranger? Also, why did Yosef accuse his brothers of being spies, which is an offense punishable by death? Yosef sent his brothers to jail for three days. When he sent them back home he kept Shimon in jail until they returned with Binyamin. Yosef knew that it would worry Yaakov when he sees his son Shimon missing. Why did Yosef do all these bad things to his brothers?
Yosef’s motive was not revenge, even though he had a good reason to hate his brothers. The Torah says (Vayikra 19:18) that you should not bear a grudge or take revenge. Yosef had good intentions: helping his brothers. Yosef wanted his brothers to suffer for their sins against Yosef in this in world rather in the World to Come. It’s much better to be punished in this world and not in the World to Come.
The brothers committed five sins: (1) they hated him and spoke harshly to him (2) when Yaakov sent Yosef to שכם to check on his brothers, they attacked him (3) they threw him in a pit (4) they sold him into slavery, and (5) they caused Yaakov a lot of worries when they brought Yosef ‘s coat to him. One approach is that Yosef decided to make his brothers suffer five times for their five sins. The suffering towards the brothers were part of Hashem’s will.
Yosef wanted to show his brothers that Hashem is in control. When the brothers first arrived they bowed down to him (like they did in Yosef’s dream). Yosef acted like a stranger to his brothers and he spoke harshly to them. Also, Yosef accused them of being spies, which is punishable by death because, one of their sins was that they wanted to kill him. Another thing Yosef did to his brothers was put them into prison like they put him into a pit. Shimon was the one who threw him into the pit so Yosef made Shimon suffer more than the other brothers by keeping him in prison longer. For their sin of selling him into slavery, he put money into their bags so they would be accused of stealing and they would be sold into slavery.
Yosef realized that Yaakov was very worried about him and he knew that Hashem would not want Yaakov to be grieved all his life. Yosef did not identify himself to his brothers at first because he wanted to see if they changed their attitudes towards him and if they regretted selling him. Then he would identify himself to his brothers in order to comfort his father.
Yosef wanted to see his father so much that he planted the goblet in Binyamin’s bag. If Binyamin was arrested, Yaakov would want to rescue him, and therefore Yaakov would come down to Egypt where Yosef could meet him. All Yosef wanted was to help his brothers and see his father well.