Kaab bin Ujra reported,

He set out with the Prophet ﷺ in a state of ihram, and his head and beard became infested with lice. Word of this reached the Prophet ﷺ, who sent for him and called the barber, who shaved his head.Then the Prophet ﷺ asked him, "Do you have an animal for sacrifice?"He replied, "I cannot afford one."So the Prophet ﷺ ordered him to fast three days, or to feed six poor people, giving every two of them one saa. Allah عز وجل then revealed concerning him specifically, "And whoever among you is ill or has an ailment of the head" [Baqarah 2:196], and the ruling later applied to all Muslims generally.

Muslim 2884

Sahih

و حدثنا أبو بكر بن أبي شيبة حدثنا عبد الله بن نمير عن زكرياء بن أبي زائدة حدثنا عبد الرحمن بن الأصبهاني حدثني عبد الله بن معقل حدثني

كعب بن عجرة رضي الله عنه

أنه خرج مع النبي ﷺ محرما فقمل رأسه ولحيته فبلغ ذلك النبي ﷺ فأرسل إليه فدعا الحلاق فحلق رأسه ثم قال له هل عندك نسك قال ما أقدر عليه فأمره أن يصوم ثلاثة أيام أو يطعم ستة مساكين لكل مسكينين صاع فأنزل الله عز وجل فيه خاصة {فمن كان منكم مريضا أو به أذى من رأسه} ثم كانت للمسلمين عامة

مسلم 2884صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Hajj
Chapter
Permissibility of shaving the head for one in Muharram if he has an ailment, the obligation of fidya for shaving it, and an explanation of its amount
Numbering
Darussalam 2884
Muslim 2884