Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
tabarani:16344ʿAbdullāh b. Muḥammad b. Saʿīd b. Abū Maryam > Muḥammad b. Yūsuf al-Firyābī > Sufyān > Ayyūb > Mujāhid > ʿAbd al-Raḥman b. Abū Laylá > Kaʿb b. ʿUjrah

[Machine] The Prophet ﷺ passed by a man who was lighting a fire under a cooking pot. The Prophet asked him, "Has your brain (i.e. mind) ordered you to do this?" The Prophet then ordered him to shave his hair and fast for three days, or to feed six poor people, or to sacrifice an animal. Sufyan said, "This verse was revealed: 'So whoever among you is ill or has an ailment of the head.'"  

الطبراني:١٦٣٤٤حَدَّثَنَا عَبْدُ اللهِ بْنُ مُحَمَّدِ بْنِ سَعِيدِ بْنِ أَبِي مَرْيَمَ ثنا مُحَمَّدُ بْنُ يُوسُفَ الْفِرْيَابِيُّ ثنا سُفْيَانُ عَنْ أَيُّوبَ عَنْ مُجَاهِدٍ عَنْ عَبْدِ الرَّحْمَنِ بْنِ أَبِي لَيْلَى عَنْ كَعْبِ بْنِ عُجْرَةَ قَالَ

مَرَّ بِهِ النَّبِيُّ ﷺ وَهُوَ يُوقِدُ تَحْتَ قِدْرٍ فَقَالَ «آذَتْكَ هَوَامُّ رَأْسِكَ؟» فَأَمَرَهُ النَّبِيُّ ﷺ أَنْ يَحْلِقَ وَيَصُومَ ثَلَاثَةَ أَيَّامٍ أَوْ يُطْعِمَ فَرَقًا بَيْنَ سِتَّةِ مَسَاكِينٍ أَوْ يَنْسُكَ قَالَ سُفْيَانُ فَنَزَلَتْ هَذِهِ الْآيَةُ {فَمَنْ كَانَ مِنْكُمْ مَرِيضًا أَوْ بِهِ أَذًى مِنْ رَأْسِهِ}  


See similar narrations below:

Collected by Muslim
muslim:1201dIbn Numayr from my father > Sayf > Mujāhid > ʿAbd al-Raḥman b. Abū Laylá > Kaʿb b. ʿUjrah

Do these vermins trouble you? I said: Yes. Thereupon he said: Then shave your head; and it was in connection with me that this verse was revealed:" Whoever among you is sick or has an ailment of the head, he (may effect) a compensation by fasting or alms or a sacrifice". He (the Holy Prophet, therefore) said to me: Observe fast for three days or give a quantity of alms enough to feed six needy persons or offer sacrifice (of an animal) that is available.  

مسلم:١٢٠١dوَحَدَّثَنَا ابْنُ نُمَيْرٍ حَدَّثَنَا أَبِي حَدَّثَنَا سَيْفٌ قَالَ سَمِعْتُ مُجَاهِدًا يَقُولُ حَدَّثَنِي عَبْدُ الرَّحْمَنِ بْنُ أَبِي لَيْلَى حَدَّثَنِي كَعْبُ بْنُ عُجْرَةَ ؓ

أَنَّ رَسُولَ اللَّهِ ﷺ وَقَفَ عَلَيْهِ وَرَأْسُهُ يَتَهَافَتُ قَمْلاً فَقَالَ أَيُؤْذِيكَ هَوَامُّكَ قُلْتُ نَعَمْ قَالَ فَاحْلِقْ رَأْسَكَ قَالَ فَفِيَّ نَزَلَتْ هَذِهِ الآيَةُ { فَمَنْ كَانَ مِنْكُمْ مَرِيضًا أَوْ بِهِ أَذًى مِنْ رَأْسِهِ فَفِدْيَةٌ مِنْ صِيَامٍ أَوْ صَدَقَةٍ أَوْ نُسُكٍ} فَقَالَ لِي رَسُولُ اللَّهِ ﷺ صُمْ ثَلاَثَةَ أَيَّامٍ أَوْ تَصَدَّقْ بِفَرَقٍ بَيْنَ سِتَّةِ مَسَاكِينَ أَوِ انْسُكْ مَا تَيَسَّرَ