After two full years in prison, Pharaoh dreamed (Genesis 41:1). The midrash reads this through Psalm 73: "As an endless dream, the Lord despised their form." God does not reveal Himself to the wicked during daylight — the encounter would shame them, like a dream dissolving in morning light. The wicked operate in obscurity, in the darkness where their deeds can remain hidden. So God meets them at night, in the dream register, where their power is already diminished.
This is also why Jacob's famous ladder dream came to him at night. The ladder, the angels ascending and descending, the divine voice at the top — none of it came in daylight when Jacob could have doubted his senses. It came in sleep, in the vulnerable space where defenses are down and the soul is open. The rabbis taught that prophecy came to the prophets in the night watches precisely because night removed the daytime noise of self-importance and self-sufficiency.
Pharaoh's dreams are different — not revelation but signal, requiring a human interpreter to decode their meaning. The fat cows devoured by the thin, the full grain consumed by the withered — these are warnings, not promises. God sends warnings to those who might act on them, even to Pharaoh, because the seven years of plenty and famine belong to Egypt's history and not only Israel's. Joseph in prison, forgotten by the butler for two full years, was precisely where God needed him to be when Pharaoh's dream required someone who knew how to receive divine communication.
Chapter (65) 66: Writings [1] A song of ascents. Many a time they have afflicted me from my youth, let Israel now say— (Psalm 129:1) See, O LORD, the distress I am in! My heart is in anguish, [*Lit. “My heart has turned over within me”; cf. Exod. 14.5; Hos. 11.8.I know how wrong I was ] To disobey. Outside the sword deals death; Indoors, the plague. (Lamentations 1:20) The Knesset of Israel said: "Master of the Universe, you saw fit for us to experience suffering, as it is written 'With him who wrote with me, I am in distress' (Psalm 91:15). Behold, we are in distress, and it is good for You. Until now, Israel would say of themselves that no one had risen up against them like Balaam the wicked. Our rabbis said in the name of Rabbi Yehuda ben Pazi that when Balak sent Balaam to curse Israel, Balaam said to him, 'What are you doing? Do you want to anger the Lord who is with them? They are like two people who are inseparable. If one of them is hit, it is as if both are hit. The Lord is like this with Israel. If I curse them, it is as if I am touching Him.' As it says, How can I damn whom God [God Heb El, as often in these poems.] has not damned, How doom when יהוה has not doomed? (Numbers 23:8). Similarly, Jeremiah says, 'For as the girdle cleaves to the loins of a man' (Jeremiah 13:11). When will this happen? When what Moses said is fulfilled: 'You shall love the Lord your God and listen to His voice, and you shall cling to Him' (Deuteronomy 30:20). Therefore, David said: "Though I walk through [*Others “the valley of the shadow of death.”] a valley of deepest darkness, I fear no harm, for You are with me; Your rod and Your staff—they comfort me. (Psalm 23:4)