To see Genesis 39 without my comments click HERE.
When Joseph arrived in Egypt he was sold to a man named Potiphar. Potiphar means Chief Butcher, which could mean head cook, but probably meant body guard.
Because Joseph was bought by Potiphar “the Lord blessed the house of Potiphar for the sake of Joseph” Jasher 44:12. This of course made Joseph a valuable asset in the house of Potiphar. In Genesis 39:6 the Bible says that Joseph was goodly (handsome) and well favored. This is believable because his mother (Rachel) in Genesis 29:17 was described as being beautiful and well favored also.
Potiphar's wife saw that Joseph was handsome and she made advances to him in which he flat out declined. Eventually one day Potiphars wife actually pulled the clothing off of Joseph and made a false claim that he tried to lay with her. She addresses him as a Hebrew v.17, this proves she was not a Hebrew herself.
If Joseph had laid with her he would have violated Potiphar's trust, but more importantly Joseph would have adulterated himself with a non-Hebrew woman which is against the commandment of Yahweh in Exodus 20:14. His actions were in direct contrast to the sexual immorality of his brothers Reuben and Judah.
There's indication that Potiphar's wife may have done this before and that Potiphar didn't believe her. This is because Potiphar could have legally had Joseph killed, but rather he chose to put him in prison when he was put on the spot by his other servants which were watching to see his next move. There is also indication at least in literature anyway, that unfaithful women were put to death because of sexual promiscuity. This obviously weighed heavily on Potiphar's decision on how to handle this false claim about Joseph by his wife. She obviously had to make up something quick when Joseph ran from the house without clothing.
The Westcar Papyrus was discovered in Egypt in 1823 by Henry Westcar. The second story of the Westcar Papyrus talks about the wife of a Chief Lector that discovers his wife is having an affair. She is bound to a stake, set on fire, and thrown in the Nile River.
Joseph trusted God even in prison. These series of events in Josephs life were to prepare him to save the House of Israel and the entire known world. Joseph being sold into slavery and being taken to Egypt, was to put him in a position to receive his power through the Pharaoh and his contacts in prison were to prepare him to be brought in front of the Pharaoh. Joseph never gave up his faith. Throughout Joseph's ordeals he put his entire faith and trust in the Lord to do with him what he wanted.
If you are an Israelite in Yahweh's (God's) grace, if you obey him, and his word, and things are still going bad, then it's only because he has a bigger plan for you in the end like what happened to Joseph. He puts you where he wants you to serve him best and more often then it's not comfortable surroundings. I pray that all Israel will emulate the example of Joseph's faith.
And we know that all things work together for good to them that love God, to them who are called according to his purpose.