The Talmud recounts David's exile from Jerusalem during Absalom's rebellion and his sojourn among nations, reading his suffering as prototypical. The Gemara also discusses David's testing and vulnerability, linking his personal galus-experience to broader theological themes.
אָמַר רַב יְהוּדָה אָמַר רַב: אֲפִילּוּ בִּשְׁעַת חׇלְיוֹ שֶׁל דָּוִד קִיֵּים שְׁמֹנֶה עֶשְׂרֵה עוֹנוֹת, שֶׁנֶּאֱמַר: ״יָגַעְתִּי בְּאַנְחָתִי אַשְׂחֶה בְכׇל לַיְלָה מִטָּתִי בְּדִמְעָתִי עַרְשִׂי אַמְסֶה״. וְאָמַר רַב יְהוּדָה אָמַר רַב: בִּקֵּשׁ דָּוִד לַעֲבוֹד עֲבוֹדָה זָרָה, שֶׁנֶּאֱמַר: ״וַיְהִי דָּוִד בָּא עַד הָרֹאשׁ אֲשֶׁר יִשְׁתַּחֲוֶה שָׁם לֵאלֹהִים״, וְאֵין ״רֹאשׁ״ אֶלָּא עֲבוֹדָה זָרָה, שֶׁנֶּאֱמַר: ״וְהוּא צַלְמָא רֵישֵׁיהּ דִּי דְהַב טָב״. ״וְהִנֵּה לִקְרָאתוֹ חוּשַׁי הָאַרְכִּי קָרוּעַ כֻּתׇּנְתּוֹ וַאֲדָמָה עַל רֹאשׁוֹ״. אָמַר לוֹ לְדָוִד: יֹאמְרוּ מֶלֶךְ שֶׁכְּמוֹתְךָ יַעֲבוֹד עֲבוֹדָה זָרָה? אָמַר לוֹ: מֶלֶךְ שֶׁכְּמוֹתִי יַהַרְגֶנּוּ בְּנוֹ? מוּטָב יַעֲבוֹד עֲבוֹדָה זָרָה וְאַל יִתְחַלֵּל שֵׁם שָׁמַיִם בְּפַרְהֶסְיָא.
Rav Yehuda says that Rav says: Even during the time of his illness he fulfilled the mitzva of conjugal rights for eighteen wives, as it is stated: “I am weary with my groaning; every night I speak in my bed; I melt away my couch with tears” (Psalms 6:7). Even when he was weary and groaning he still spoke in his bed, a euphemism for sexual intercourse. And Rav Yehuda says that Rav says: David sought to engage in idol worship during Absalom’s coup, as it is stated: “And it came to pass when David was at the top [rosh] of the ascent, where he would bow to God” (II Samuel 15:32), and rosh means nothing other than idol worship, as it is stated: “As for that image, its head [reishei] was of fine gold” (Daniel 2:32). It is written: “Behold Hushai the Archite came to meet him with his coat rent and earth upon his head” (II Samuel 15:32). Hushai said to David: Shall they say a king like you will engage in idol worship? David said to him: Is it preferable that they say with regard to a king like me, known to be righteous, that his son will kill him? David continued, referring to himself in third person: It is preferable that he shall engage in idol worship and the name of Heaven shall not be desecrated in public through the murder of a righteous king in this manner.