In Parashat Shofetim, we learn that when the Jewish people entered the land of Israel, they were commanded to perform three Mitzvot: appoint a king, destroy Amaleik, and build the Beit HaMikdash. The Gemara (Sanhedrin 20b) notes that these three Mitzvot must be performed in Eretz Yisrael, and later these Mitzvot were codified by Rambam (Hilchot Melachim 1:1). Rambam adds, in the second Halachah of Hilchot Melachim, that these commandments must be done in the specific order - first appoint a king, then destroy Amaleik, and finally build the Beit HaMikdash.
Later, in Sefer Shmuel, Shmuel HaNavi is infuriated when the Jews request a king (I Shmuel 8:6). Why would this be? Doesn’t that request for a leader seem to be the fulfillment of the Mitzvah that the nation was given to appoint a king? Many suggest that the request was not motivated by a desire to fulfill the Mitzvah. Rather, it was indicative of a rebellion against Hashem, as Hashem told Shmuel, “They rebelled against me” (8:7). The Jewish nation was, unfortunately, searching for a leader to replace Hashem.
The Gemara (Sanhedrin 20b) presents three opinions regarding Jewish monarchy. The majority of the Amora’im in that Gemara are of the opinion that monarchy is an undesirable form of government. However, Rambam codifies the apparent minority opinion that appointing a kind is indeed a Mitzvah. On the other hand, Abarbanel (Devarim 17) is strongly opposed to the idea of having a king. He believes kingship is unnecessary for Am Yisrael. He postulates that the Torah meant that if the people ask for a king, a Jewish monarch may be appointed in such a situation, but it is definitely not the ideal.
Rav Binyamin Tabory, in The Weekly Mitzvah, writes that even though there are concerns about the Jewish People’s intentions when they requested a king, it is interesting to note that in the end, a king is appointed.
The Vilna Gaon (commentary to Parashat VaYeishev) points out that a “Melech” (king) is appointed by God, and a “Mosheil” (dictator) is self-appointed. Hashem is a Melech to the Jews, who accept His kingship; however, He is only a Mosheil to the non-Jews, as we state in Tefillah, “Ki LaHashem HaMeluchah UMosheil BaGoyim.” We hope and pray for the day when Hashem does not feel that the Jews have rebelled against Him, the day when Hashem will truly be a Melech to everybody and accepted by all, “VeHayah Hashem LeMelech Al Kol HaAretz.”