We pick up the narrative from chapter 37.
v1: Joseph is bought by Potiphar, one of Pharoah's officials.
v2: The Lord blesses Joseph, and that is evident to others.
v3-6: The Lord blesses Potiphar for Joseph's sake; it was clear that God was with him (see Matt 27.54). Joseph was faithful (v6). Joseph was given increasing responsibility (Luke 16.10-12). We are encouraged to be faithful in whatever situation God has called us (1 Cor 7.20-24).
v7: Increasing responsibility can bring new temptation.
v8-10: Joseph faced repeated and persistent temptation (see Matt 4.1-11). The enemy will attack frequently, so that our guard drops or we become weak, like Samson (Judg 16.16). Joseph chose the way of obedience and purity; to sin is an offence firstly against God (Ps 51.4; Luke 15.18,21), and secondly against Potiphar and Potiphar's wife. Adultery and fornication damages relationships; with God, and with others. Joseph contrasts sharply with Judah (ch 38) here.
v11: "It happened" (RAV); the circumstances turn against Joseph. He is in the wrong place at the wrong time. We need to be constantly vigilant, for the enemy is constantly active (1 Peter 5.8). Yet we have confidence in God, for nothing surprises Him.
v12: Joseph takes decisive action, to resist temptation, and to avoid sin; he runs away.
v13-18: Joseph is falsely accused of wrong-doing (see Luke 23.2). Note that Joseph is described as a Hebrew (v14.17), indicating that he was distinctive.
v19-20: Joseph is immediately imprisoned (see Mark 14.65). There is no trial and argued defence. Jesus Christ was similarly silent (see Luke 23.9).
v21-23: Joseph is faithful in prison, the new situation (Prov 16.7). There is no word of grumbling, complaint, or bitterness. Nor does Joseph seek favour - he just finds it. He is in prison for a total of 13 years.
Giralamo Savonarola’s final book was ‘Rule for a Good Christian Life’ whilst in prison awaiting martyrdom. His jailer was so impressed with his dignity and godly life, and asked him to provide him with guidance how to live such a life.
God's ways are higher than our ways. He places His servants in "surprising" places. Moses spent 40 years in the desert looking after sheep. David spent years in obscurity, and years fleeing from Saul. Yet God does not make mistakes.