It is impossible not to be hurt by someoneelses sin in this world. You can see that in the news today. So this story of Joseph and his enslavement is showing us that God is at work even in the trials of life. God has a good plan for his people even if it involves trials and suffering. According to Genesis 50:20 we know that there are 2 levels to this story. One is the story of Jacob and his sons -- especially Joseph, and the second level is the story of God's secret providence. We have seen the hatred against Joseph, and now we continue to see God Providence that is a good plan even if it involves trials.
We first see God's providence in his restraining hand -- he did not let the brothers of Joseph do what they first wanted to do - "Kill him." The brothers mocked Joseph and God's revelation which indicates that they had no faith in God. We must understand that God's providence uses instruments like you and me (Secondary causes). God work the strife in the family to accomplish his goal and guided that strife as well. Remember God meant it for good, that means that he is the ultimate cause while not responsible for evil or sin. Ruben prevented the immediate death of Joseph but God at another level was working that out in the life of Ruben. All came to pass infallibly yet according to secondary causes. God accomplishes through voluntary actions of men (secondary causes) his will. Sometimes we see God's direct providence but most often as here we wee God's indirect providence in using instruments of his creation.
We also see God's providence in his grace toward Joseph in sending him to Egypt away from his brothers who hated him. The Ishmaelite / Midianite traders were an unexpected opprotunity for Joseph's brothers but it was all brough about by God's meticulous providence. I don't think Joseph knew of God's providence, as we do not many times in the middle of trials. Sometimes God's providence rescues us from trials (ex: 2 Kings 6:13-17) and sometimes God's providence restricts harm but doesn't answer our crys they way we make them.
We continue to see God's providence in the coverup, because it gave the time that was needed for Joseph to become leader in Egypt and rescue his family. It also gave time for conviction to settle in on the brothers because of their circumstances. Just as in the circumstances that led to the death of Christ for our sins, Joseph's live at the second level was being orchestrated by God for good.
God uses everything and is the ultimate cause of everything for good. He is not the author of sin or is in any way responsible for the voluntary sin of mankind. From the cruelty of Joseph's brothers, to the intensity of the family strife, to the trail of slavery, God will restore and grant love between this family. It is God's way. God's providence is wise, good, loving, and just. Do you bow the knee and say, "What ever God ordains is right!"