The Talmud teaches that the Shekhinah does not rest upon one who is in a state of sadness (atzvut), laziness, or frivolity, but only upon one who performs a mitzvah with joy — establishing the foundational rabbinic link between simcha and the indwelling of Divine presence.
״וְשִׁבַּחְתִּי אֲנִי אֶת הַשִּׂמְחָה״ — שִׂמְחָה שֶׁל מִצְוָה. ״וּלְשִׂמְחָה מַה זֹּה עוֹשָׂה״ — זוֹ שִׂמְחָה שֶׁאֵינָהּ שֶׁל מִצְוָה. לְלַמֶּדְךָ שֶׁאֵין שְׁכִינָה שׁוֹרָה לֹא מִתּוֹךְ עַצְבוּת וְלֹא מִתּוֹךְ עַצְלוּת וְלֹא מִתּוֹךְ שְׂחוֹק וְלֹא מִתּוֹךְ קַלּוּת רֹאשׁ וְלֹא מִתּוֹךְ שִׂיחָה וְלֹא מִתּוֹךְ דְּבָרִים בְּטֵלִים, אֶלָּא מִתּוֹךְ דְּבַר שִׂמְחָה שֶׁל מִצְוָה, שֶׁנֶּאֱמַר: ״וְעַתָּה קְחוּ לִי מְנַגֵּן וְהָיָה כְּנַגֵּן הַמְנַגֵּן וַתְּהִי עָלָיו יַד ה׳״. אָמַר רַב יְהוּדָה: וְכֵן לִדְבַר הֲלָכָה. אָמַר רָבָא: וְכֵן לַחֲלוֹם טוֹב.
Similarly, “So I commended mirth,” that is the joy of a mitzva. “And of mirth: What does it accomplish?” that is joy that is not the joy of a mitzva. The praise of joy mentioned here is to teach you that the Divine Presence rests upon an individual neither from an atmosphere of sadness, nor from an atmosphere of laziness, nor from an atmosphere of laughter, nor from an atmosphere of frivolity, nor from an atmosphere of idle conversation, nor from an atmosphere of idle chatter, but rather from an atmosphere imbued with the joy of a mitzva. As it was stated with regard to Elisha that after he became angry at the king of Israel, his prophetic spirit left him until he requested: “But now bring me a minstrel; and it came to pass, when the minstrel played, that the hand of the Lord came upon him” (II Kings 3:15). Rav Yehuda said: And, so too, one should be joyful before stating a matter of halakha. Rava said: And, so too, one should be joyful before going to sleep in order to have a good dream.