If God was with Yosef, why did he sit in prison for so long?
The psalm tells it in a few lines. Verse 16: God "called a famine." Verse 17: He "sent a man ahead of them," Yosef, sold as a slave. Verse 18: his feet in chains. Verse 19: "until His word came, the word of Hashem refined him." It does not say why it took so long.
One answer is that the story was bigger than Yosef. Rashi says the "word" is God's decree that Israel would go down to Egypt. On verse 17 he points to what Yosef told his brothers: "God sent me ahead of you" (Bereishit 45:5). Midrash Tehillim adds the calf that leads the cow. And near the end of the Torah, Yosef says: you meant harm, God meant it for good (Bereishit 50:20).
A second answer looks at Yosef himself. Rashi says verse 19 is about the test with his master's wife. Yosef held firm, and because of her he suffered, was refined, and was put in prison. Midrash Tehillim gives a reason the wait grew longer: Yosef asked the cupbearer to remember him, and two more years were added.
A third answer reads "his word" as the end of the wait. Radak says it is the moment the cupbearer finally spoke to Pharaoh about Yosef. God brought this about through Pharaoh's dream, which only Yosef could explain, and Yosef came before Pharaoh "like refined silver." Metzudat David (a commentary on the Prophets and Writings from the 1700s) says the word of Hashem refined Yosef's own words, so his explanation of the dream had no error in it.
These readings do not cancel each other, and the sources do not choose one. None of them explains why one person has to carry so much for a larger plan. The psalm gives the whole wait one verse and moves on.
Rashi on Tehillim 105:16-19,Midrash Tehillim 105:5-6,Radak and Metzudat David on Tehillim 105:19,Bereishit 45:5, 50:20Why does a thank-you psalm spend so long on famine, slavery and prison?
Look at verses 12 to 22. A few people with no land of their own, moving from kingdom to kingdom. A famine. A brother sold. Chains. The psalm opens with "Give thanks," and then comes this.
Radak, on verse 5 ("Remember His wonders"), says that for even one miracle a person must remember the earlier ones. On that reading, telling the long story is part of the thanks.
The Ve'al Kulam section of the Amidah tells the rest of this story: the rule in the Mishnah (the first written collection of the rabbis' teachings) that a person must bless God for the bad as for the good, and the night Rabbi Akiva (a great sage of the Mishnah) spent in a field. The Mishnah's word for that thanks, modeh, comes from the same root as this psalm's first word, hodu.
The Gemara on that Mishnah adds one more step. It asks what "must bless for the bad" means, since the blessing for bad news has different words from the blessing for good news. Rava (a sage of the Gemara) answers: to accept the bad with joy.
That is a lot to ask. The Gemara does not say the bad part stops hurting, or that every story ends well. Yosef's does, in the verses ahead. Many people's do not, and the sources we opened do not explain that gap.
Radak on Tehillim 105:5,Mishnah Berakhot 9:5,Berakhot 60bI know what I should do. Why do I forget it right when it matters?
The Gemara asks this about the inner voice that says do the right thing. Rami bar Abba (a sage of the Gemara) reads a verse in Kohelet (Ecclesiastes) as a parable. A small city with few people is the body with its limbs. A great king who surrounds it is the evil inclination. A poor, wise man in the city is the good inclination. Then the verse says no one remembered that poor man. The Gemara explains: when the evil inclination takes over, no one remembers the good one (Nedarim 32b).
Mei HaShiloach (Rabbi Mordechai Yosef Leiner of Izhbitz, a Chassidic teacher of the 1800s) uses that line on verse 4 of this psalm: "Seek Hashem and His strength, seek His face always." A person must know the weak spots of his own heart, he says, and accept fear of Heaven before the test comes. In the moment, nobody reminds you of the good inclination. All the advice is before the test, and what you limit in advance helps you during it. That, he says, is "seek His face always."
The psalm's own example of someone under pressure is Yosef. Rashi says he held firm. Bereishit Rabbah (the classic Midrash on Bereishit) pictures how. Each time his master's wife threatened him, he answered with a line of praise to God. She said she would cut his food. He said, "He gives bread to the hungry." She said she would chain him. He said, "Hashem frees the imprisoned." The Midrash does not say he rehearsed those lines. It shows that when the pressure came, they were in his mouth.
Nobody here promises it works every time. Mei HaShiloach only says where the work is: before the test, not during it. Rebbe Nachman's ten psalms are said after a lapse. This verse is about before.
Nedarim 32b,Mei HaShiloach, Volume 2, on Tehillim 105,Rashi on Tehillim 105:19,Bereishit Rabbah 87:10