Devarim / Deuteronomy 16:18 · Drash
שֹׁפְטִים וְשֹׁטְרִים תִּתֶּן־לְךָ בְּכָל־שְׁעָרֶיךָ אֲשֶׁר יְהוָה אֱלֹהֶיךָ נֹתֵן לְךָ לִשְׁבָטֶיךָ וְשָׁפְטוּ אֶת־הָעָם מִשְׁפַּט־צֶדֶק׃
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.
Drash דְּרָשׁ
The judge's tree
It is hard to demand of another what you do not do yourself. The midrash tells of a judge who reached for a saw before he gave a ruling.
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
Midrash Tanchuma Judges and officers
Judges must be strong in good deeds. So did Moshe: "And Moshe chose capable men" (Shemot / Exodus 18:25), in Torah, in good deeds and in strength. And they must be clear of every charge, so that no one has a reason to say a word against them. Like Moshe, who said to Israel: "I have not taken one donkey from them" (Bamidbar / Numbers 16:15). And like Shmuel, who said: "Here I am, testify against me before the Eternal and before His anointed: whose ox have I taken, and whose donkey have I taken" and so on (Shmuel I / I Samuel 12:3). So you must say: "judges and officers", so that there is nothing unfit in them.
There was a case with Rabbi Chanina ben Elazar. He had a tree planted in the middle of his field, and its branches leaned over another field. A man came, complained before him and said: "So-and-so's tree leans over my field." Rabbi Chanina said to him: "Go and come back tomorrow." The man said: "Every case that comes before you, you decide at once, and my case you put off." What did Rabbi Chanina do? At once he sent his workers and cut down the tree that stood in the middle of his field and leaned over another field. The next day that man came before him for judgment. Rabbi Chanina said to his opponent: "You must cut it down." The opponent said: "And why do the branches of your tree lean over another field?" Rabbi Chanina said to him: "Go out and look: as you see what I did with mine, so do with yours." The man went at once and did so. That is why it is written: "judges and officers", so that there is nothing unfit in a judge.
Takeaway
"I have not taken one donkey from them" are Moshe's words during Korach's rebellion. "Whose ox have I taken" are Shmuel's words when the people asked for a king. Both judged the people and took nothing from them.
The Talmud tells a similar story of Rabbi Yannai: his tree hung over a public road, and he cut it down before judging another. There it says: "Correct yourself first, then correct others" (Bava Batra 60a).
Kli Yakar on the Remez level reads the same lesson in the words "appoint for yourself": correct yourself first.