(כט) וַיָּ֤שׇׁב רְאוּבֵן֙ אֶל־הַבּ֔וֹר וְהִנֵּ֥ה אֵין־יוֹסֵ֖ף בַּבּ֑וֹר וַיִּקְרַ֖ע אֶת־בְּגָדָֽיו׃ (ל) וַיָּ֥שׇׁב אֶל־אֶחָ֖יו וַיֹּאמַ֑ר הַיֶּ֣לֶד אֵינֶ֔נּוּ וַאֲנִ֖י אָ֥נָה אֲנִי־בָֽא׃ (לא) וַיִּקְח֖וּ אֶת־כְּתֹ֣נֶת יוֹסֵ֑ף וַֽיִּשְׁחֲטוּ֙ שְׂעִ֣יר עִזִּ֔ים וַיִּטְבְּל֥וּ אֶת־הַכֻּתֹּ֖נֶת בַּדָּֽם׃ (לב) וַֽיְשַׁלְּח֞וּ אֶת־כְּתֹ֣נֶת הַפַּסִּ֗ים וַיָּבִ֙יאוּ֙ אֶל־אֲבִיהֶ֔ם וַיֹּאמְר֖וּ זֹ֣את מָצָ֑אנוּ הַכֶּר־נָ֗א הַכְּתֹ֧נֶת בִּנְךָ֛ הִ֖וא אִם־לֹֽא׃ (לג) וַיַּכִּירָ֤הּ וַיֹּ֙אמֶר֙ כְּתֹ֣נֶת בְּנִ֔י חַיָּ֥ה רָעָ֖ה אֲכָלָ֑תְהוּ טָרֹ֥ף טֹרַ֖ף יוֹסֵֽף׃ (לד) וַיִּקְרַ֤ע יַעֲקֹב֙ שִׂמְלֹתָ֔יו וַיָּ֥שֶׂם שַׂ֖ק בְּמׇתְנָ֑יו וַיִּתְאַבֵּ֥ל עַל־בְּנ֖וֹ יָמִ֥ים רַבִּֽים׃

(29) When Reuben returned to the pit and saw that Joseph was not in the pit, he rent his clothes. (30) Returning to his brothers, he said, “The boy is gone! Now, what am I to do?” (31) Then they took Joseph’s tunic, slaughtered a kid, and dipped the tunic in the blood. (32) They had the ornamented tunic taken to their father, and they said, “We found this. Please examine it; is it your son’s tunic or not?” (33) He recognized it, and said, “My son’s tunic! A savage beast devoured him! Joseph was torn by a beast!” (34) Jacob rent his clothes, put sackcloth on his loins, and observed mourning for his son many days.
ויקרע את בגדיו. ביעקב כתיב שמלותיו לפי שהוא קרע כל בגדיו אף הסמוכים לעורו כדכתיב היא שמלתו לעורו:

וַיִּקְרַ֖ע אֶת־בְּגָדָֽיו, “he rent his outer garments.” When his father heard about Joseph’s apparent death, the Torah describes the rending of his garments with the words וַיִּקְרַ֤ע שִׂמְלֹתָ֔יו, “he rent his (under)garments.” When mourning parents or children, one rends all of one’s clothing, whereas when mourning siblings one only rends outer garments. The word שמלה appears as covering for one’s skin” (Exodus 22,26)

These pasukim are the first ones in the תנך that talk about ripping your clothes when a family member died. Although this is the first time, just some unknown midrashim learn the Halacha from this.

רב מנחם מנדל כשר זצ"ל (Chumash Torah Shalem) asks the question why the Gmara in Moed Katan doesn't learn from this pasuk.

There are two main reasons why the gemara doesn't learn it from this pasuk.

1.) It looks like it is a natural reaction for humans, as Reuven and Yaakov did it without getting told to by 'ה.

2.) It is a machloket (Talmud Yerushalmi Moed Katan Perek 3) if we are learning form things Am Israel did before Matan Torah.

From this we can learn that even though it isn't a Halacha it is very important to go with the natural instinct when it isn't against the Halacha.