1 Peter 3:17 (NKJV) says, "For it is better, if it is the will of God, to suffer for doing good than for doing evil."
Joseph is a perfect example of this.
Joseph fled from the adulterous temptations offered to him by Potiphar's wife. In Genesis 39:9 (NKJV), Joseph said to her, "How then can I do this great wickedness, and sin against God?"
Given Joseph's courageous and principled stand against sin, one would think that he would be rewarded and blessed abundantly for it.
Instead, he was sent to prison.
Joseph did the right thing.
Joseph did good.
And God let him suffer for it.
God's thoughts and God's ways are not the same as ours, according to Isaiah 55:8-9, and the same holds true for God's will and God's logic. They are all on a higher level and a higher plane than our own. We assume that our good actions always will be amply blessed by God, at least according to our murky, cloudy, and human-logic-based understanding of divine blessing.
Perhaps you have done good.
And perhaps you are now suffering for it.
Please know that God has not forsaken you. He has not forgotten you. He has not dropped the ball. In His sovereign will, and as part of His sovereign plan, He is allowing you to endure precisely what He has placed in your life.
In the case of Joseph, it all worked out perfectly in the end, as God used what others meant for evil instead for good in the life of Joseph (Genesis 50:20).
God will do the same in your life, too, even if you presently are suffering for doing good.