The commandment to rejoice on Sukkot is just one of a number of obligations that concern one's mood.
The Jewish calendar designates days of contemplation, of mourning, and of joy.
Though at first sight it may seem to be a paradox, it can be said that only he who has the strength to mourn on Tishah b'Av (the anniversary of the destruction of the Temple and of other disasters in Jewish history) is capable of rejoicing on Simchat Torah.
In spite of the apparent polar differences between the two activities, there is a profound bond between them, for both draw upon the same inner strength.
The ability to rejoice on a preassigned day derives from self-discipline, which is an integral part of the religious life and an essential characteristic of the religious Jew.
–Rabbi Adin Steinsaltz
From "A Time for Joy," an essay in The Strife of the Spirit by Rabbi Adin Steinsaltz