עַתָּה֩ לֵ֨ךְ וְהִכִּֽיתָ֜ה אֶת־עֲמָלֵ֗ק וְהַֽחֲרַמְתֶּם֙ אֶת־כָּל־אֲשֶׁר־ל֔וֹ וְלֹ֥א תַחְמֹ֖ל עָלָ֑יו וְהֵמַתָּ֞ה מֵאִ֣ישׁ עַד־אִשָּׁ֗ה מֵֽעֹלֵל֙ וְעַד־יוֹנֵ֔ק מִשּׁ֣וֹר וְעַד־שֶׂ֔ה מִגָּמָ֖ל וְעַד־חֲמֽוֹר׃ (ס)
Теперь иди и порази Амалика, и истреби все, что у него; но убей и мужчину и женщину, младенца и сосунка, быка и овцу, верблюда и осла.' ,
Mishneh Torah, Kings and Wars
The appointment of the king comes before the war with Amalek, as it says, “G-d has sent me to anoint you king…Now, go and smite Amalek” (I Samuel 15:1-3). The eradication of Amalek precedes the construction of the Temple, as it says, “and it was so, when the king was settled in his home, and G-d allowed him respite from his enemies all around. And the king said to Nathan, the Prophet, ‘I am living in a house of cedar…’” (II Samuel 7:1-2). Now, since the appointment of a king is a Commandment, why did G-d not want (a king) when the people asked Samuel for one? Because their request was merely due to resentment, and not for the purpose of fulfilling a Commandment. They had rejected Samuel the Prophet, as it says, “as they have forsaken Me…so do they also with you” (I Samuel 8:7).