What a terrible thing it is when believers fall into sexual sin. After David fell into sin with Bathsheba, the prophet Nathan said to him, "By this deed you have given great occasion to the enemies of the LORD to blaspheme" (2 Samuel 12:14). In other words, "David, you just gave ammunition to the enemy."
I wish Christians would think about that before they sin. Joseph did. When Potiphar's wife made her advances, Joseph understood there were consequences to sin. He said, "There is no one greater in this house than I, nor has [Potiphar] kept back anything from me but you, because you are his wife. How then can I do this great wickedness, and sin against God?" (Genesis 39:9). Joseph was loyal to Potiphar. Of course, Potiphar would end up betraying Joseph. But Joseph wouldn't betray Potiphar.
Joseph could have rationalized it. Hey, man, I had a rough childhood. I was sold into slavery by my brothers. I am here all alone in Egypt. It's hard being alone. Egyptian culture—that is the way it is here. It doesn't really matter.
He could have said a lot of things, but Joseph understood that God's standards are absolute. They don't change. He also realized that all sin is against God. This should be our strongest deterrent against sin—not merely our fear of the repercussions. The greatest deterrent against sin is loving God. If you love God, you want to do things that honor Him.
I like this statement of Augustine's: "Love God and do as you please." If you really love God as you ought to, with all your heart, all your soul, and all your mind, then you will only want to do what pleases Him. Jesus said, "If you love Me, keep My commandments" (John 14:15).