EXTRA · Parashas Vayeishev · Passuk 39:20 · not a Torah Temimah citation on this passuk
So Joseph’s master had him put in prison, where the king’s prisoners were confined. But even while he was there in prison,
Classical source (EXTRA side-ring): Bereshis Rabbah 87:10.
Sefaria — Bereshis Rabbah 87:10
English: “And he put him into the prison” — R’ Abbahu said: I only have [Hashem’s presence] in prosperity; from where even in distress? The verse says: And Hashem was with Yosef.
Derash on the verse (Bereshis Rabbah) — not a formal named middah of the 13. Prison becomes the proof-text for presence in suffering.
Hashem’s being “with Yosef” is demonstrated as much in the dungeon as in Potiphar’s house.