Joshua — how happy he was! He slew thirty-one kings, gave Israel the land as an inheritance and divided it, and all Israel lent him their shoulder and said (Joshua 1:18): "Any man who rebels against your command [and does not obey your words in all that you command him shall be put to death]" — something which Moses our teacher did not merit. Yet he did not abide in his happiness, but rather died without sons. Therefore it is said (Psalms 75:5): "I said to the exultant: Do not exult."
Joshua Conquered Thirty-One Kings Yet Died Without Sons
Midrash Tanchuma Buber, Shmini 3:6
יהושע כמה שמח, הרג שלשים ואחד מלכים, והנחיל לישראל את הארץ וחילקה, ונתנו לו כל ישראל כתף, ואמרו כל איש אשר ימרה את פיך וגו' (יהושע א יח), מה שלא זכה משה רבינו, ולא המתין בשמחתו, אלא מת בלא בנים, לכך נאמר אמרתי להוללים אל תהולו.