Sukkot is z'man simchatenu -- the season of our rejoicing. But the megilla associated with it is Kohelet (Ecclesiastes), which is a downer and somewhat depressing. Why? Sources say it is to provide a counterweight to unbridled rejoicing. Perhaps so, but the problem is that the Torah says: Vesamachta bechagecha, vehaita ach sameach -- You will rejoice in your holiday, you will ONLY rejoice. [Deuteronomy 16:14-15] The word "only" seems to exclude "counterweights". So what is the resolution? (Note: Most Sephardim don't read Kohelet on Sukkot.)
There is an explanation of the meaning of simcha that is appropriate to Kohelles. Kohelles - the wisest of men – explains in vivid detail, that all of the temporal pleasures and enjoyments of this world are vanity and futility. When all is said and done, it is only Fear and Love of Hashem and fulfillment of His Will that grants a sense of inner joy and purpose. And therein lies the message of Succos. Kohelles is not a counterweight, it is an explanation of what actually causes simcha.
Malbim explains that simcha refers to internal gladness which is continual, while sasson is the external expression of one's inner happiness. In other words, sasson denotes what a person does to show that he is happy, for example wearing special clothes for holidays or playing music at happy times, while simcha is the happy feeling inside of him. Thus, Kohelles teaches us that only recognizing that only following Hashem leads to simcha.
Chabad points out that succos is also chag ha-asif, the festival of the harvest. This can lead to complacency and an attempt to find simcha in the results of the harvest (whether it be good or better) which is olam hazeh. Kohelles reminds us that everything is from Hashem, and that is the only lasting simcha.
A major theme of Kohelet is the futility of mundane pursuits and pleasures, and the search for deeper meaning to life. Sukkot is also known as Chag ha-Asif—the Festival of Ingathering. It’s the time of year when the harvest has ended, and the crops are gathered and stored for the coming year. It’s a moment of great satisfaction, as one can see the fruits of his labor before him.
Kohelet shakes our contentment with the reminder that mundane accomplishments are fleeting and empty. Even at the close of the harvest, we must seek real achievement and fulfillment.
Sukkot itself demonstrates this theme by the commandment to live in temporary dwellings. We move outside our home, which provides a sense of permanence and comfort, and instead dwell in a flimsy hut. This recalls the transience of physicality, as does the book of Kohelet.
There are also a number of answers at Why do we read Kohelet on Sukkos? which use this theme to point out the connection of succos and Kohelles