Qoheles in a Nutshell
While tradition skips over the who said to whom before identifying the significant word or two to take as the text’s name, there are exceptions, notably Vayiqra (both the parashah and the book) and Qoheles.
Focusing on Qoheles, there is good reason for that:
דִּבְרֵי קֹהֶלֶת בֶּן דָּוִד מֶלֶךְ בִּירוּשָׁלִָם.
The words of Qoheles son of David, king in Yersushalayim: (1:1)
“Ben David” is not enough to justify our identification of Qoheles with Shelomo; “ben David” refers to any descendent of David, as in “Mashiach ben David”.
Rashi (ad loc) quotes the medrash’s explanations of the name. The first is because he gathered wisdom, also in the medrash R’ Yehudah associates this gathering with the name Agur, not Qoheles. The second idea in Rashi appears is described at more length in the medrash:
קהלת למה נקרא שמו קהלת שהיו דבריו נאמרין בהקהל על שם שאמר (מ”א ח:א): “אָז יַקְהֵל שְׁלֹמֹה…”
“Qoheles”: Why was his name called “Qoheles”, because his ideas were said a Haqhel, as it says “Then Shelomo gathered…” (Melakhim I 8:1)
Shelomo wrote three books: Mishlei, Qoheles and Shir haShirim. Rabbi Chiya Ruba says he first wrote Mishlei, then Shir haShirim, then Qoheles. Rabbi Yonasan says it was first ShS then Mishlei, but yes Qoheles was last. (Shir haShirim Rabba 1:1:10). Rabbi Yonasan’s is the more often quoted position, because it appears to smoothly match psychology: the young man starts life with the Romance of Shir haShirim, when Middle Aged, he has the focus of Mishlei, and the elder who has seen it all and done it all writes Qoheles.
According to the Targum on 1:2, the tone of Qoheles is more than the surliness we might associate with old age, “כד חזא שלמה מלכא דישראל ברוח נבואה ית מלכות רחבעם בריה דעתיד למתפלגא עם ירבעם בר נבט — Shelomo haMelekh saw with a prophetic spirit that the kingdom of his son Rechav’am would in the future be split with Yeravam ben Nevat.
By calling himself Qoheles, Shelomo drives home a very sad point, he was the only king to gather the Jews to the Beis haMiqdash the Sukkos after Shemittah to fulfill the mitzvah of Haqhel. Before him there was no Beis haMiqdash, and shortly after his passing Yeravam takes 10 of the shevatim as a separate kingdom and forbids their attending the Beis haMiqdash. “I am Qoheles, the son of David” — Shelomo was the only one.
Qoheles was written when the king realized that everything he built, even that which he tried to build for G-d and at His command, would not survive.
Which colors how we read his conclusion in the last verses of the book (12:13-14):
סוֹף דָּבָר הַכֹּל נִשְׁמָע אֶת הָאֱלֹקים יְרָא וְאֶת מִצְוֹתָיו שְׁמוֹר כִּי זֶה כָּל הָאָדָם. כִּי אֶת כָּל מַעֲשֶׂה הָאֱלֹקים יָבִא בְמִשְׁפָּט עַל כָּל נֶעְלָם אִם טוֹב וְאִם רָע.
The end of the matter, everything having been heard: have yir’ah for G-d, and observe His mitzvos, for that is the entirety of a person. For G-d will bring every hidden thing to judgment, whether it is good or evil.
Don’t measure yourself by progress, not even building spiritual edifices. Just develop one’s own spirituality, one’s yir’as Shamayim, observe halalkhah — that’s a person’s job. The outcome? That’s His Judgment.