The commandment to rejoice on Sukkot is just one of a number of such 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.
–Rabbi Adin Steinsaltz
From The Strife of the Spirit, p. 93, by Rabbi Adin Steinsaltz