If my brothers had hated me enough to sell me to traders I am pretty sure I wouldn't have welcomed them with open arms. At first that seems to be Joseph's reaction as he pretends not to know them and questions them. But we then can see there is a reason besides hurt feelings or revenge for Joseph's methods.
So why does he pretend to be a stranger and question them harshly, if not to punish them? It is clear from his questions that before telling them who he is, Joseph wants to learn more about them and test them. No doubt he has wondered all those years how things have fared with his family. Have his brothers changed in all those years? How is their relationship now with their father? Joseph is also concerned about his brother Benjamin, who is not with them. Have they done away with him, too? And if not, will Jacob trust them enough to send Benjamin? Joseph must know these things before they can be reconciled.All quoted material is from Catholic Exchange's "Catholic Scripture Study." See the sidebar under "Bible Study: Genesis" for links to references used.
So Joseph tests his brothers not to taunt or punish them, but with the aim of bringing them to true repentance and ultimately to reconcile them with himself and with their father. In this, he gives us a picture of what Christ will do one day for his brothers: not just forgive them and free them from sin for their own sakes, but restore them to friendship and into the family of God (See CCC #1443).
All Joseph's testing aims to bring them to repentance and reconciliation. Three days in prison gave the men real time to worry about their predicament. They were being asked to bring their youngest brother to Egypt, and if they had never sold Joseph, Benjamin would be with them now. They were confined in prison, which may have reminded them that they held Joseph in a pit regardless of his pleas and sold him into the prison of slavery. Their consciences began to accuse them. They realized that they did wrong against Joseph and deserve this punishment, which they see as coming from God. They have acknowledged their sin, which is the first step toward repentance. Evidence of true sorrow and a changed character remain to be seen.
As much as Joseph must have longed to see Benjamin, sending his brothers to get him posed a further test as much as it would bring about a reunion. Were the brothers still jealous, divided against their father's favorite? Had their relationship with their father improved? Would he trust them with Benjamin? These questions remain to be answered.