Moed Katan 15b
מועד קטן ט״ו ב — ד"ה אָבֵל אָסוּר בְּתַשְׁמִישׁ הַמִּטָּה
Moed Katan 15b:10
A mourner is prohibited from engaging in sexual relations during the mourning period, as derived from the verse describing David's comforting of Bath-Sheba after their son's death, which implies that such relations were initially forbidden.
אָבֵל אָסוּר בְּתַשְׁמִישׁ הַמִּטָּה, דִּכְתִיב: ״וַיְנַחֵם דָּוִד אֵת בַּת שֶׁבַע אִשְׁתּוֹ וַיָּבֹא אֵלֶיהָ״, מִכְּלָל דְּמֵעִיקָּרָא אָסוּר.
§ The Gemara considers another issue: A mourner is prohibited from engaging in sexual relations, as it is written: “And David comforted Bath-Sheba his wife, and went into her, and lay with her” (II Samuel 12:24), after their son had died. This proves by inference that initially, during the period of mourning, sexual relations were forbidden.