It is narrated about Sayyiduna Ka'b bin Ujrah (may Allah be pleased with him) that he set out with the Prophet (peace and blessings be upon him) in the state of ihram, and lice got into his head and beard. This reached the Prophet (peace and blessings be upon him), so he (peace and blessings be upon him) sent someone to him and called the barber, who shaved his head. Then he said: "Do you have a sacrificial animal?" He said: "I cannot afford it." So he (peace and blessings be upon him) ordered him to fast three days or feed six poor people, one sa' for each poor person. Then Allah, the Mighty and Majestic, revealed this verse specifically concerning him: "And whoever among you is ill or has an ailment of the head, then a ransom of fasting, or charity, or a sacrifice" [Surah al-Baqarah: 196]; then this ruling became general for all Muslims.
Hadith Referenceالمعجم الكبير للطبراني / باب الكاف / 16352