Recently, a cousin of mine lost his father. Before conducting a ritual for the well being of his father's soul, he had to shave all his hair except for a bit at the back (choti). Why did he have to do this?
It's because the funeral rites mentioned in Garuda Purāṇa say so.
From Chapter 4, Preta Kāṇḍa (Dharma Kāṇḍa) of Garuda Purāṇa:
Śrī Kṛṣṇa said:
कि दानमिति प्रश्नस्योत्तरमीरितम्॥ दाहमृत्योरन्तरे किमिप्रश्नोत्तरं शृणु ॥४०॥
40. I have given the answer to your queries about gifts. Now, I shall tell you about the obsequies and the funeral rites of the deceased.
प्रेतपिण्ड प्रदद्याच्च दाहातिशमनं खग॥ ततः प्रदक्षिणां कृक्त्वा चिताप्रस्थानवीक्षकाः॥ ६९॥
कनिष्ठपूर्व्वाः स्नानार्थं गच्छेयुः सूक्तजापकाः॥ ततो जलसमीपे तु गत्वा प्रक्षाल्य चांशुकम्॥७०॥
69-70. O bird, Preta-pinda is given in order to comfort the deceased. Then having circumambulated the pyre and casting a mournful look at it, the mourners should go for bath muttering the hymn, with the youth marching ahead.
71. Then having reached water and washed cloth, they should wear the same saying for the deceased — we are taking bath.
कुरुध्वमित्येव विदेच्छतवर्षावरे पुत्राद्या वृद्धपूर्वास्ते एकवस्त्राः शिखांविना॥७२॥
प्राचीनावीतिनः सव्र्वे विशेयुर्मौनिनो जलम्॥ अपनःशोशुचदघमनेन पितृदिङमुखाः॥७३॥
72-73. Then they all, each wearing one cloth only, with shaven heads, wearing the sacred thread over the right shoulder should enter water silently.
जलावघट्टनं चैव न कुय्र्युः स्नानकारकाः॥ ततस्तटे समागत्या शिखां बद्धा ऋजून् कुशान्॥७४॥
दक्षिणाग्रहस्तयोस्तु कृत्वाथ सतिलं जलम्॥ आदायाद्भलिना याम्यां दुःखी पैतृकतीर्थतः॥७५॥
एकवारं त्रिवार वा दशवारमथापि वा। भूमावश्मनि वा सव्र्वे क्षिपेयुर्वाग्यताः खग।॥७६॥
74-76. The bathers should not agitate water. Then coming out of the water to the bank, tying their Sikha (knot of hair in the center of the head) they should take in their right hand kusas and water with the gingelly seeds (sesame) and offer the same in the southern direction, pouring it from the paitrka-tirtha over the earth silently once, thrice or ten times.
And from Chapter 5, The Annual Rite:
एवं जलस्याञ्जलयो विभाज्याः पक्षयोर्द्वयोः॥
सव्र्वेषु पितृकाय्येषु पुत्रो मुख्योऽधिकारवान्॥ २६॥
26. O bird, thus the water-offering is divided. For performing the rites of the manes, the son is the proper person.
पिण्डप्रसेकस्तूष्णीञ्च पुष्पधूपादिकं तथा॥
दशमेऽहनि सम्प्राप्ते स्नानं ग्रामाद्वहिश्चरेत्॥२७॥
27. Pinda-praseka shall be done in silence and with flowers, incense, etc. On the tenth day, bath should be taken outside the village.
तत्र त्याज्यानि वासांसि केशमश्रुनखानि च॥
विप्रः शुध्यत्पः स्पृष्ट्वा क्षत्त्रियो वाहनं तथा॥ २८॥
वैश्यः प्रतोदं रश्मीन्वा शूद्रो यष्टिं कृत क्रियः॥
मृतादल्पवयोभिश्च सपिण्डैः परिवापनम्॥ २९॥
28-29. Then they should leave their old clothes, hair, beard and nails. Brahmana is purified by touching water, Ksatriya by touching vehicle, Vaisya by touching a goad (or a whip) or reins, and Sudra by touching stick after performing the rites. The relatives, younger in age, should undergo shave.
In doing all of the above, the objective is to purify oneself after a death in the family which is considered a period of aśauca (अशौच).
As mentioned earlier in the same chapter:
अपनोद्यन्त्विदं कालादिभिराशु निषेधकृत्॥ निण्डाध्ययनदानादेः पुंगतोऽतिशयो हि तत् ॥९॥
दशाह शावमाशौच सपिण्डेषु विधीयते॥ जननेऽप्येवमेव स्यान्निपुणां शुद्धिमिच्छताम् ॥१०॥
9-10. The ten-day-period of aśauca is prescribed for the relatives of the deceased on the father's side. This commences from the hour of birth, also with a view to obtain purity.
Also, from this answer, the Dharma Sindhu is supposed to contain the following verse which suggests that, for everyone, their pāpa is attached to the hair; so by getting rid of your head hair, symbolically, you are getting rid of your pāpa or sins and then qualify for visiting a sacred pilgrimage site. The same reasoning can be applied to removal of one's hair during funeral rites.
tIrthopavAsa kartavya sirasomundanAnicha sirogatAni pApAni yAntimandanatho yatah