It is narrated from Sayyiduna Ka'b bin Ujrah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) saw him while his lice were falling onto his face, and said: "Are your lice troubling you?" He said: Yes. So the Messenger of Allah (peace and blessings be upon him) ordered him to shave his head at al-Hudaybiyah, while at that time it was not clear to them that they would shave their heads there, as they were hoping to enter Makkah. Then Allah, the Mighty and Majestic, revealed the verse of ransom, and the Messenger of Allah (peace and blessings be upon him) ordered him to feed one faraq to six poor people, or to offer a goat as a sacrificial animal (hady), or to fast three days.
Hadith Referenceالمعجم الكبير للطبراني / باب الكاف / 16276