All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
The impurity of the dog was subject to different views among scholars. The majority are of the view that all its parts are impure. In Al-Mughni, Ibn Qudaamah said:
"Things which are impure are of two types: First, what is impure by consensus, which is the dog and the swine as well as what comes from either or both of them. Their bodies, remnants of their drink and all types of discharges are impure. This is reported on the authority of ‘Urwah. It is also the opinion of Ash-Shaafi‘i and Abu ‘Ubayd. It is the opinion of Abu Haneefah regarding the remnant of drink in particular. Maalik, Al-Awza‘i and Daawood said, "Their remnant is pure and it is useable for Wudhoo’ (ablution) and drinking. When they lick food, it is not rendered unlawful to eat."
Mentioning the dog in the story of the Companions of the Cave does not mean that it is pure. That is because the mentioned dog did not mix with them. Rather, it was guarding them outside the door and was not inside the cave, as the angels do not enter a place where there is a dog or an image. Commenting on the story, Ibn Katheer quoted Ibn Jurayj as saying: "It was guarding them at the door, as this is the dog's job and nature. It was resting at the door as if it was guarding them. It was outside because the angels do not enter a home were there is a dog, as mentioned in the authentic Ahaadeeth."
Commenting on the story, Al-Qurtubi said: "Most of the scholars of Tafseer (interpretation, explanation) hold the opinion that it was a true dog and that it belonged to one of them who used it for hunting or guarding his farm or sheep, according to what Muqatil said."
Even if we assumed that the dog mixed with the Companions of the Cave and deduced that it was pure for them, there is the principle that the laws of those before us are not applied when we have our own relevant laws. It is known that the dog is impure in the Islamic law.
Allaah Knows best.