(Reporting the speech of Kaʿb bin Umra) Messenger of Allah ﷺ saw him (i.e. Kaʿb) while the lice were falling on his face. He asked (him), "Have your lice troubled you?" He replied in the affirmative. So, he ordered him to get his head shaved while he was at Al-Hudaibiya. At that time they were not permitted to finish their Ihram, and were still hoping to enter Mecca. So, Allah revealed the verses of Al-Fidya. Messenger of Allah ﷺ ordered him to feed six poor persons with one Faraq of food or to slaughter one sheep (as a sacrifice) or to fast for three days. (Using translation from Bukhārī 1817)
أَنَّ رَسُولَ اللهِ ﷺ رَآهُ وَقَمْلُهُ يَسْقُطُ عَلَى وَجْهِهِ فَقَالَ «أَيُؤْذِيكَ هَوَامُّكَ؟» قَالَ نَعَمْ فَأَمَرَهُ رَسُولُ اللهِ ﷺ أَنْ يَحْلِقَ بِالْحُدَيْبِيَةِ لَمْ يَتَبَيَّنْ لَهُمْ أَنَّهُمْ يَحْلِقُونَ وَهُمْ عَلَى طَمَعٍ أَنْ يَدْخُلُوا مَكَّةَ فَأَنْزَلَ اللهُ ﷻ الْفِدْيَةَ فَأَمَرَهُ رَسُولُ اللهِ ﷺ أَنْ يُطْعِمَ فَرَقًا بَيْنَ سِتَّةِ مَسَاكِينٍ أَوْ يَهْدِيَ شَاةً أَوْ يَصُومَ ثَلَاثَةَ أَيَّامٍ