Medrash Vayeishev: Potifar's Wife, Some People Just Never Give Up
Yosef's alleged crime against Potifar's wife was punishable by death. Why did they put him in jail and not execute him? Different Medrashim offer various answers. According to the Medrash Rabba, it was obvious that she was lying and Yosef was not guilty. Potifar had him jailed so people wouldn't say that Potifar's children were probably not really his, since his wife was so promiscuous.
Another Medrash says that it was Osnas that told her father the truth. Because of this Hashem said, "Since it was you that saved Yosef, the two Shevatim that will come from him will be from you."
The Medrash Tanchuma says that it was Potifar's wife who suggested he spare Yosef. She told him to keep him in jail until he finds a buyer for him, and recovers the money he paid for him. The Medrash says that the reason she did this was because she still hoped to have relations with him. Every day while he was in jail, she would go visit him and try again!