(14) When thou art come unto the land which the LORD thy God giveth thee, and shalt possess it, and shalt dwell therein; and shalt say: ‘I will set a king over me, like all the nations that are round about me’; (15) thou shalt in any wise set him king over thee, whom the LORD thy God shall choose; one from among thy brethren shalt thou set king over thee; thou mayest not put a foreigner over thee, who is not thy brother. (16) Only he shall not multiply horses to himself, nor cause the people to return to Egypt, to the end that he should multiply horses; forasmuch as the LORD hath said unto you: ‘Ye shall henceforth return no more that way.’ (17) Neither shall he multiply wives to himself, that his heart turn not away; neither shall he greatly multiply to himself silver and gold. (18) And it shall be, when he sitteth upon the throne of his kingdom, that he shall write him a copy of this law in a book, out of that which is before the priests the Levites. (19) And it shall be with him, and he shall read therein all the days of his life; that he may learn to fear the LORD his God, to keep all the words of this law and these statutes, to do them; (20) that his heart be not lifted up above his brethren, and that he turn not aside from the commandment, to the right hand, or to the left; to the end that he may prolong his days in his kingdom, he and his children, in the midst of Israel.
And the LORD answered Moses, “Single out Joshua son of Nun, an inspired man, and lay your hand upon him. Have him stand before Eleazar the priest and before the whole community, and commission him in their sight. Invest him with some of your authority, so that the whole Israelite community may obey. But he shall present himself to Eleazar the priest, who shall on his behalf seek the decision of the Urim before the LORD. By such instruction they shall go out and by such instruction they shall come in, he and all the Israelites, the whole community.” Moses did as the LORD commanded him. He took Joshua and had him stand before Eleazar the priest and before the whole community. He laid his hands upon him and commissioned him—as the LORD had spoken through Moses.
Why was the matter bad in HaShem’s eyes? – Because they demanded it complainingly, and not for the sake of the mitzvah. Had they said, Give us a king who will judge us with honesty and faith, the matter would not have been bad in Samuel’s eyes;… or had they said, We will follow your advice in appointing a king over ourselves since you have grown old, and this king will judge us and chastise us, and fear of him will be upon us so that we will keep G-d’s ways – then this request would have been good. But when they said, ‘Give us a king’, this was bad and a lack of trust in G-d, especially as they added ‘…like all the nations’”.
-Radak (R. David Kimchi)