The five scrolls are noted for their liturgical use, being traditionally read on various holidays. Some of the connections seem rather straight forward (e.g. Esther on Purim or Lamentations on the Ninth of Av). I'm curious, though, how Ecclesiastes came to be associated with Sukkot (known to some as the Feast of Booths)? There appears at least no direct connection between the two. What elements led the communities that have this liturgical practice to link the two together?
Rashi sets forth two reasons for the connection, and other commentators have other interesting ideas.
Rashi states first that the verse "Divide a portion into seven, and even into eight for you don't know what troubles shall be upon the earth" (Eccl. 11:2), refers to Succot, referring to a Midrash, Kohelet Rabbah 11:2, which quotes one opinion that the reference in the verse to seven and eight is an allusion to Succot which is a seven day holiday with an additional day holiday at the end.
A second reason that can be inferred from Rashi's commentary to Eccl. 1:1 concerning the name Solomon (aka Shlomo) uses to describe himself - Kohelet - which comes from the root קהל which means to gather. Solomon spoke the words contained in Ecclesastes at the Hakel (הקהל) which is the gathering of the people at the Temple during the Succot of the Shmitah (Sabbatical) year.
Rabbi David Abudraham (14th century) relates Rashi's second interpretation to our tradition to read Kohelet on Succot:
There is another reason and that is that Shlomo said these words on Succot as it states (Deut. 31:10) on the holiday [at the conclusion] of the shemitah year, on Succot, when the Jewish people come to be seen, gather the nation, the men, women and children, etc. and it states (Kings I 8:2) they all gathered to King Shlomo during the month of Etanim, on Succot, etc. and it was then that he recited [Kohelet] during hakhel in order to rebuke the Jewish people. For this reason, it is logical to recite it on Sukkot. This is from the writings of Ibn HaYarchi. (Sefer Abudraham, Tefillot HaPesach.)
According to R. Naftali Z.Y. Berlin (The Netziv, 1816-1893), King Solomon's gathering was of a slightly different nature:
In the fourteenth chapter of Zechariah it states that in the future, the nations of the world will come on Chol HaMoed of Succot to stand next to their offering because they will also recognize the sovereignty of God, the King … This was also the tradition during the days of Shlomo and for this reason, Shlomo would recite Kohelet on Chol HaMoed Succot to the nations of the world … For this reason, we have been reciting Kohelet throughout the generations on Chol HaMoed Sukkot. (Harchev Davar, Bamidbar 29:12.)
Another reason often mentioned is that Ecclesastes' rather depressing tone is a counter to the joyfulness of the Succot holiday and the celebration of Simchat Torah and Shemeni Atzeret which follow. Eccl. 2:2 asks the question, "what does joy accomplish?" The Gemara at Shabbat 30b teaches:
R. Yehuda son of R. Samuel b. Sheilat said in Rav's name: The Sages wished to conceal the Book of Ecclesiastes, because its words are self-contradictory; yet why did they not conceal it? Because its beginning is religious teaching and its end is religious teaching. Its beginning is religious teaching, as it is written, What benefit does man get for of all his labor that he labors under the sun? And the School of R. Yannai commented: Under the sun he has none, but he has benefit before the sun. The end is religious teaching, as it is written, Let us hear the conclusion of the matter, fear God, and keep his commandments: for this is the whole of man. What is meant by, ‘for this is the whole of man’? - Said R. Eliezar, The entire world was created only for the sake of this [type of] man. And how are its words self-contradictory? … It is written, Then I commended joy; but it is written, and of joy [I said] What does it accomplish?" There is no difficulty …‘Then I commended joy’: this refers to the joy of a commandment. ‘And of joy [I said], what does it accomplish’: this refers to joy [which is] not in connection with a commandment. (Adapted from Soncino Translation.)
In other words, reading Ecclesiastes tempers the joy of Succot by reminding us that true joy is only achieved when it is the context of our service of God.