All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
First of all, we say that dyeing hair with a pure black color is subject to a difference of opinion among the scholars. The majority of the scholars held that it is disliked, and the Shaafi'i School held that it is forbidden.
The view which we adopt here at Islamweb is that there is no harm in using the oil that is used for treatment, even if it leads to turning the hair black, provided that it does not include any impurity and does not cause any harm. In this case, it is used as a treatment and not for dyeing with black, especially given that the forbiddance of dyeing with black that is mentioned in the hadeeth is not explicit in prohibiting it [it may only mean that it is disliked].
The scholars said regarding the incident wherein the Prophet forbade the Companions from dyeing the hair of Abu Quhaafah black that it was because of his appearance (his old age). Dyeing with black is only suitable for those who have a radiant (youthful) face, but in Abu Quhaafah's case, it would be shameful because it would not suit someone with his appearance, and there is no problem with that.
Az-Zuhri said, "We used to dye with black when we were young (had a radiant face), but when our face started to wrinkle and our teeth started to fall, we stopped doing it."
The narration of the Prophet that some people at the end of time will dye with black does not indicate that it is forbidden. The Prophet informed us that the sign of the Kharijites is that they shave their heads, and no one has ever said that it is prohibited to shave the head because of that.
Since there is no explicit statement that indicates the prohibition and the majority of the scholars are of the view that it is only disliked [and not forbidden], we do not restrict the one who needs a treatment for hair fall from using it, even if the treatment leads to changing the gray hair to black.
Allah knows best.