וַיֹּ֤אמֶר הַמֶּ֙לֶךְ֙ אֶל־נָתָ֣ן הַנָּבִ֔יא רְאֵ֣ה נָ֔א אָנֹכִ֥י יוֹשֵׁ֖ב בְּבֵ֣ית אֲרָזִ֑ים וַֽאֲרוֹן֙ הָֽאֱלֹהִ֔ים יֹשֵׁ֖ב בְּת֥וֹךְ הַיְרִיעָֽה׃
что царь сказал Нафану пророку: 'Видите, я живу в кедровом доме, но ковчег Божий обитает в завесах.'
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).