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 · Pshat

Devarim 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

A people chooses who will lead it. The Torah sets conditions: who chooses, and from among whom.

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

Chizkuni Whom the Eternal will choose

Through a prophet or through the Urim and Tummim.

Chizkuni You may not

You are able, but you are not permitted.

Chizkuni Set a foreigner over you

Lest he draw you to serve what he fears.

Ibn Ezra You shall set

This is a permission.

Ibn Ezra Whom He will choose

Through a prophet or by the judgment of the Urim. And the sense is: not the one you choose.

Haamek Davar From among your brothers and so on

That is, if they do not merit a prophet, then at least "from among your brothers": that he be of noble lineage.

Haamek Davar You may not and so on

Noble lineage is only a commandment where possible, not a condition: for Herod was not of the noble families of Israel, and still he had the law of a king. But a foreigner cannot be made king over Israel in the Land of Israel.

Takeaway

The Urim and Tummim (אוּרִים וְתֻמִּים) were placed in the breastplate of the high priest. Through them the Eternal was asked about the affairs of the people (Shemot / Exodus 28:30, Bamidbar / Numbers 27:21).
"What he fears" is Chizkuni's name for the foreigner's god: what he stands in awe of and serves.
Ibn Ezra reads "you shall set" as a permission: if you want a king, set one. Onkelos renders "you may not" as "you have no right" (לֵת לָךְ רְשׁוּ), like Chizkuni.
Herod was king of Judea in Second Temple times, from a family that came to Judaism from outside. Haamek Davar gives him as an example of a king not of noble lineage.