(Exodus 17:16:) "And he said: Because a hand is upon the throne of the LORD, the LORD has a war with Amalek from generation to generation." It is taught in the name of Rabbi Eleazar: The Holy One, blessed be He, swore an oath and said, "My right hand, my right hand; My throne, My throne! If gentiles come from any of the nations, I will accept them; but from the seed of Amalek I will not accept." And David also acted thus, as it is said (in II Samuel 1:13): "And David said to the young man who told him: From where are you? And he said: I am the son of an Amalekite sojourner." Rabbi Isaac said: He was the son of Doeg the Edomite. And David said to him (in II Samuel 1:16): "Your blood be upon your own head." ["Your bloods" is written.] Much blood you spilled in Nob, the city of the priests.
God's Oath Barring the Seed of Amalek and David's Sentence on the Amalekite
Midrash Tanchuma Buber, Ki Teitzei 18:1
ויאמר כי יד על כס יה מלחמה לה' בעמלק (שמות יז טז), תני בשם ר' אלעזר, שבועה נשבע הקב"ה, ואמר ימיני ימיני, כסאי כסאי, אם יבואו גוים מכל האומות אני מקבלן, ומזרעו של עמלק איני מקבל, ואף דוד עשה כן, שנאמר ויאמר דוד אל הנער המגיד לו אי מזה אתה ויאמר בן איש גר עמלקי אנכי (ש"ב א יג), אמר ר' יצחק בנו של דואג האדומי היה, ויאמר לו דוד דמך על ראשך (שם שם טז), [דמיך כתיב], הרבה דמים שפכת בנוב עיר הכהנים.