Devarim16:18

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

Judges and officers you shall appoint for yourself in all your towns that the Eternal your Almighty gives you, by your tribes, and they shall judge the people with righteous judgement.

Devarim 16:18

שֹׁפְטִים וְשֹׁטְרִים תִּתֶּן־לְךָ

Devarim / Deuteronomy 16:18

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

Judges and officers you shall appoint for yourself in all your towns that the Eternal your Almighty gives you, by your tribes, and they shall judge the people with righteous judgement.

Pshat פְּשָׁט

A court in every town

Rashi: judges give the ruling, and officers make people carry it out. A court sits in every town and for every tribe, and the judges must be expert and righteous. Haamek Davar: the whole community must watch that the judges judge justly, and the head of a town answers for the court of his town.

How Rashi and Haamek Davar explain it

Remez רֶמֶז

Yourself first

Kitzur Ba'al HaTurim: in the word "your towns" (שְׁעָרֶיךָ) you hear "to assess" (מְשַׁעֵר): a court is needed wherever another's money is assessed. "And they shall judge" (וְשָׁפְטוּ) has the same letters as "a small coin" (וּפָשׁוּט): a case over a trifle is judged as carefully as a case over a large sum. Kli Yakar: "appoint for yourself": first correct yourself, then judge the people.

How Kitzur Ba'al HaTurim and Kli Yakar explain it

Drash דְּרָשׁ

The judge's tree

Midrash Tanchuma: judges must be strong in good deeds and free of any reproach, like Moshe (Moses) and Shmuel (Samuel). Rabbi Chanina ben Elazar had a tree whose branches leaned over another's field. When a man came to him with a case about such a tree, he first cut down his own, and the next day told the defendant to do the same.

How Midrash Tanchuma explain it

Sod סוֹד

The judge within

Shem MiShmuel: "appoint for yourself" is said to everyone, and the "gates" are the gates of the heart, the five senses. The judge in a person is the mind: it decides whether the path is straight. But that is not enough: an officer is needed, so that the heart bends its nature and obeys the mind.

How Shem MiShmuel explain it