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

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.

Pshat פְּשָׁט

A court in every town

There are rules everywhere, but who settles a dispute, and who makes sure the ruling is carried out? The portion opens with two offices.

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

Rashi Judges and officers

Judges are the judges who give the verdict. And officers are those who make the people carry out their ruling: they strike with a stick and a strap and bind, until a person accepts the judge's ruling.

Rashi In all your towns

In every single town.

Rashi For your tribes

This refers to the words "appoint for yourself": judges and officers appoint for yourself for your tribes in all your towns, which the Eternal your Almighty gives you.

Rashi For your tribes

This teaches that judges are seated for every tribe and in every town.

Rashi And they shall judge the people

Appoint expert and righteous judges, so that they judge justly.

Haamek Davar And they shall judge the people with a just judgment

This too is a warning to the community of Israel: to watch over the judges, so that they judge justly. And the responsibility rests on it as well. From here we learn about the head of a town: he is obliged to watch over the court of his town. This is what is said in the midrash on Kohelet on the verse "And I hated life" (Kohelet / Ecclesiastes 2:17): Rabbi Oshaya heard that the judges of his town were dishonest, and he said: "And I hated life." Because watching over this was on him, and their guilt was on his head.

Takeaway

Onkelos renders "officers" (שֹׁטְרִים) as פֻרְעָנִין, "collectors": those who enforce a verdict. Rashi explains the same.
"In all your towns" is in Hebrew "in all your gates" (שְׁעָרֶיךָ): the court sat at the town gate.
The midrash on Kohelet is the midrash on Ecclesiastes (Kohelet Rabbah). There Rabbi Oshaya applies Kohelet's verse to himself: life is not dear to him while his town judges dishonestly.
"The responsibility rests on it" is an image in the original: "the collar hangs on their neck too".