"And showing kindness to thousands" (Exodus 20:6): one might think only to one's own offspring; therefore it says, "to the thousandth generation" (Deuteronomy 7:9). Were this verse to say only that, I would say He shows kindness only for a thousand generations; and from where do we learn thousands and thousands of thousands? Therefore it says, "and showing kindness to thousands." "To those who love Me": to one who acts before Me out of love. "And to those who keep My commandments": to one who acts before Me out of fear. This is to make known how many levels there are between one who acts out of love and one who acts out of fear; and to teach you that the measure of goodness is greater than the measure of punishment by five hundred to one. Another interpretation: four negative commands are stated in this verse — why? Corresponding to the four kingdoms. The Holy One, blessed be He, said to Israel: take heed that they not lead you astray; do not do this, do not do that. Why? Because I am destined to exact punishment from them in the end, as it is written, "For I the LORD your God am a jealous God." "Visiting the iniquity of the fathers" — the iniquity of Nebuchadnezzar, who is the father of the kingdoms — "upon the children," this is his son Belshazzar. "Upon the third" — this is the kingdom of Media, for so it says, "and it had three ribs in its mouth" (Daniel 7:5). "Upon the fourth" — this is the kingdom of Greece, of which it is written, "and the beast had four heads" (Daniel 7:6). "Of those who hate Me" — this is the wicked kingdom of Edom, of which it is written, "and Esau I hated" (Malachi 1:3). And afterward, "showing kindness to thousands, to those who love Me." From here you learn that the Holy One, blessed be He, does not cause His Presence to rest upon Zion until He has exacted punishment from the nations, and so it says, "and I will hold their blood guiltless that I have not held guiltless, for the LORD dwells in Zion" (Joel 4:21).
Mercy to Thousands and the Four Kingdoms Hidden in One Verse
Mekhilta DeRabbi Shimon Ben Yochai 20:6
ועושה חסד לאלפים יכול ליוצאי ירך בלבד ת"ל (דברים ז' ט') לאלף דור: יאמר זה שאלו כן הייתי אומר הא אינו עושה אלא לאלף דור ומניין לאלפים ולאלפי אלפים ת"ל ועושה חסד לאלפים: לאהבי. למי שעושה לפני מאהבה: ולשמרי מצותי. למי שעושה לפני מיראה: להודיעך כמה מעלות יש בין העושה מאהבה לעושה מיראה וללמדך שמדת הטוב מרובה יתר ממדת פורעניות על אחת חמש מאות: ד"א נאמר בפסוק זה ארבעה לאוין למה כנגד ארבע מלכיות אמר הקב"ה לישראל ראו שלא יטעו אתכם לא תעשה כך לא תעשה כך: למה שאני עתיד ליפרע מהן בסוף דכתיב כי אנכי ה' אלהיך אל קנא פוקד עון אבות עונו של נבוכדנצר שהוא אב של מלכיות על בנים זה בנו בלשאצר: על שלשים זו מלכות מדי שכן הוא אומר (דניאל ז' ה') ותלת עלעין בפומה: על רבעים זו מלכות יון שכתוב בה (שם ו') וארבעה רישין לחיותא: לשנאי זו מלכות אדום הרשעה שכתוב בה (מלאכי א' ג') ואת עשו שנאתי: ואחר כך ועושה חסד לאלפים לאהבי מכאן אתה למד שאין הקב״ה משרה שכינתו בציון עד שהוא נפרע מן האומות וכן הוא אומר (יואל ד' כ"א) ונקיתי דמם לא נקיתי וה' שוכן בציון: