So he began with their bags before his brother's bag. Then he brought it out of his brother's bag. It was such that We planned for Joseph, for he would not have been able to take his brother under the King's system, except that God wished it so. We raise the degrees of whom We please, and over every one of knowledge is the All Knowledgeable.
Translation endnotes
[12:76] This verse raises the dilemma of choosing between legal and moral alternatives. If laws are based on reason and universal principles, they usually do not create such dilemmas. However, even the best and most just laws, occasionally deny justice in some special cases. Then, a person might find himself in a conundrum: the legal and moral virtue of applying the law consistently, or the moral imperative of suspending the application of the law to bring about justice. Here, we are informed that as an officer of the Egyptian government, Joseph is using the laws of Israel rather than the Egyptian law. This was perhaps illegal, but was it also immoral? Joseph could defend his action by claiming that his illegal action did not harm anyone, and he had a good intention. Indeed, this intentionally good "trick" ends the tragedy and pain of a big family.