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

Devarim 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.

Remez רֶמֶז

Yourself first

It is easy to see the mistakes of others and hard to see your own. In the words of the verse the commentators hear where judgment begins.

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

Kitzur Ba'al HaTurim In all your towns (בְּכָל שְׁעָרֶיךָ)

In everything in which you assess (מְשַׁעֵר) your fellow's money: both for taxes and when you set how much to give to tzedakah.

Kitzur Ba'al HaTurim For your tribes, and they shall judge

This teaches that a judge is obliged to judge his own tribe. "And they shall judge" (וְשָׁפְטוּ) has the same letters as "a small coin" (וּפָשׁוּט): let a case over a small coin be as dear to you, to look into it closely, as a case over a hundred coins (מָנֶה). "Judges" (שֹׁפְטִים), "and they shall judge" (וְשָׁפְטוּ), "judgment" (מִשְׁפַּט): here are three words, from which money cases are judged by three.

Kli Yakar And they shall judge the people with a just judgment

By way of hint one can say: wherever "the people" is said, it speaks of the wicked, as Rashi explained on the verse "And the people were as complainers" (Bamidbar / Numbers 11:1). And our sages said: "When the litigants stand before you, let them be in your eyes as wicked" and so on (Avot 1:8). That is why it says "and they shall judge the people": during the judgment let them be in your eyes like the rest of the people, the name by which the wicked are called. But "with a just judgment": after the judgment the wickedness turns into righteousness, for they will be in your eyes as righteous once they have accepted the verdict upon themselves.

Another explanation: "Judges and officers appoint for yourself": correct (קַשֵּׁט) yourself first (Bava Metzia 107b), and afterwards "they shall judge the people": correct another. For any judge from whom money can be taken by a ruling is no judge (Bava Batra 58b).

Takeaway

שְׁעָרֶיךָ ("your gates", in the translation "your towns") and מְשַׁעֵר ("assesses") share the root ש־ע־ר. Kitzur Ba'al HaTurim hears in the gates of the court the assessment of money.
וְשָׁפְטוּ ("and they shall judge") and וּפָשׁוּט ("a small coin") are the same five letters in another order: ו ש פ ט ו. The count is checked.
A maneh (מָנֶה) is a large silver coin, a hundred dinars. The Talmud teaches: "Let a case over a perutah be as dear to you as a case over a hundred maneh" (Sanhedrin 8a).
Tzedakah (צְדָקָה) is help for the poor. The town court set how much each person gave.
"Correct yourself first, then correct others": this is how the Talmud reads the prophet's words "Gather yourselves (הִתְקוֹשְׁשׁוּ) and gather" (Tzefanyah / Zephaniah 2:1): the word קַשֵּׁט sounds like הִתְקוֹשְׁשׁוּ (Bava Metzia 107b).
"No judge" is one who himself holds what belongs to another: such a judge cannot demand it of others (Bava Batra 58b).