Judah’s voluntary sexual misbehavior contrasts starkly with Joseph’s refusal to sin sexually even under duress.
Judah found himself doubly condemned for condemning Tamar for a sin that he had also committed (Genesis 38:26); this challenges the conventional sexual double standard commonly observed in antiquity for men and women. The following contrast with Joseph drives home this point further.
Joseph was attractive (Genesis 39:6); the text does not count relevant whether Potiphar’s wife was. It also does not inform us whether Potiphar had given Joseph a female partner, which might befit Joseph’s rank in the household. It may depend partly on whether most of the some thirteen years Joseph spent in Egypt before his exaltation (Genesis 37:2; Genesis 41:46) was spent in Potiphar’s household or in prison; a mate was likelier in the former circumstance than in the latter. The narrator does not inform us whether Joseph struggled with temptation; it is simply clear that he refused to sin against God and against Potiphar.
If Potiphar was a literal eunuch (the Hebrew designation appears for Potiphar in both Genesis 37:36 and Genesis 39:1, as if emphatically), the struggle of Potiphar’s probably younger wife would not be surprising (albeit still a case of sexual harassment). The term might simply designate any officer, however (it appears also in Genesis 40:2, 7; cf. 1 Samuel 8:15; Jeremiah 29:2). In any case, Joseph recognizes that betraying the trust of Potiphar and sinning with his wife would be a sin against God himself (Genesis 39:8-9).