Joseph was able to see in the long run that what his brothers had intended for evil God used for good. If he had never been sold into slavery he'd have never met the Pharaoh and wouldn't have been in the position to order preparations to be made for the coming famine. Thousands would have starved, possibly including Jacob and his household, had things not worked out the way they did.
Treating them badly would not reflect his respect and fear of God. Joseph saw his brothers' change of heart, and mercifully forgave them. Godly fear moved Joseph to conquer evil with good. Romans 12:17,18 "Return evil for evil to no one. Provide fine things in the sight of all men. If possible, as far as it depends upon you, be peaceable with all men."
He had mercy, and pity for his brothers. He had God on his side, and He gave Joseph the strength to forgive them. He loved his brothers, and he was acting Godly to them because he cared about his whole family. And his brothers did change. You see, he had always forgiving them. He didn't hold a total grudge over them. That's just truly amazing. He tested his brothers, and found they really did have a change of heart.
Perhaps most profoundly, Joseph's story presents amazing insight into how God sovereignly works to overcome evil and bring about His plan. After all his ordeals, Joseph is able to see God's hand at work. As he reveals his identity to his brothers, Joseph speaks of their sin this way: "Do not be distressed and do not be angry with yourselves for selling me here, because it was to save lives that God sent me ahead of you. . . It was not you who sent me here, but God" (Genesis 45:5, 7-8). Later, Joseph again reassures his brothers, offering forgiveness and saying, "You intended to harm me, but God intended it for good" (Genesis 50:20). Man's most wicked intentions can never thwart the perfect plan of God.http://www.gotquestions.org/life-Joseph.html
Because he knew that what had happened to him was according to God's Will. And that's our problem today because to many times we blame God for the terrible things that happen in our lives when we don't see the full picture. If it causes people to come to Jesus it's all worth it.