Devarim17:15

שׂוֹם תָּשִׂים עָלֶיךָ מֶלֶךְ אֲשֶׁר יִבְחַר יְהוָה אֱלֹהֶיךָ בּוֹ מִקֶּרֶב אַחֶיךָ תָּשִׂים עָלֶיךָ מֶלֶךְ לֹא תוּכַל לָתֵת עָלֶיךָ אִישׁ נָכְרִי אֲשֶׁר לֹא־אָחִיךָ הוּא׃

you shall surely set over yourself a king whom the Eternal your Almighty will choose. From among your brothers you shall set a king over yourself. You may not put over yourself a foreigner who is not your brother.

Devarim 17:15

שׂוֹם תָּשִׂים עָלֶיךָ

Devarim / Deuteronomy 17:15

שׂוֹם תָּשִׂים עָלֶיךָ מֶלֶךְ אֲשֶׁר יִבְחַר יְהוָה אֱלֹהֶיךָ בּוֹ מִקֶּרֶב אַחֶיךָ תָּשִׂים עָלֶיךָ מֶלֶךְ לֹא תוּכַל לָתֵת עָלֶיךָ אִישׁ נָכְרִי אֲשֶׁר לֹא־אָחִיךָ הוּא׃

you shall surely set over yourself a king whom the Eternal your Almighty will choose. From among your brothers you shall set a king over yourself. You may not put over yourself a foreigner who is not your brother.

Pshat פְּשָׁט

A king from your brothers

Chizkuni and Ibn Ezra: the Eternal chooses the king, through a prophet or through the Urim and Tummim, not you yourself. You are able to set a foreigner over you, but you are not permitted: he may draw you to serve his god. Haamek Davar: "from among your brothers" means a man of noble lineage. This is only a commandment, not a condition: Herod was not of noble lineage and was still king. But a foreigner cannot be made king over Israel.

How Chizkuni, Ibn Ezra, and Haamek Davar explain it

Remez רֶמֶז

Thirty steps

Kitzur Ba'al HaTurim: "you shall set over you" equals in numerical value "thirty steps": kingship is acquired by thirty qualities. "From among your brothers" equals "from the tribe of Yehudah (Judah)". Agra DeKala: the name Yehudah (יְהוּדָה) hides the Name of the Eternal. "Whom He will choose" means chosen for good, like the house of David.

How Kitzur Ba'al HaTurim and Agra DeKala explain it

Drash דְּרָשׁ

Agrippa's tears

Sifrei: "a foreigner": from here a leader of the community is appointed only if his mother is from Israel. When King Agrippa read this verse he wept, and the people told him: "You are our brother." The Talmud adds: the sages praised Agrippa for reading standing. But Rabbi Natan said: at that hour the people earned punishment, because they flattered him.

How Sifrei and Talmud, Sotah explain it

Sod סוֹד

The king is the heart

Mei HaShiloach: a king "from among your brothers" is one whose heart is good to all, like David, who pitied his sheep. "The foreigner" is a man of anger: anger has no share in Israel. Ba'al Shem Tov: the king in Israel is the heart, and the heart "hears", that is, understands.

How Mei HaShiloach and Ba'al Shem Tov explain it