Praise be to Allah.
Fasting on the first eight days of Dhul-Hijjah is mustahabb (recommended) for pilgrims and others. This is because the Prophet Muhammad (peace and blessings of Allaah be upon him) said: “There are no days in which good deeds are more beloved to Allaah than these ten days.” They said: O Messenger of Allaah, not even jihad for the sake of Allaah? The Messenger of Allaah (peace and blessings of Allaah be upon him) said: “Not even jihad for the sake of Allaah, unless a man goes out with his self and his wealth and comes back with neither.” (Narrated by Al-Bukhaari (969) and al-Tirmidhi (757), from the hadeeth of Ibn ‘Abbaas (may Allaah be pleased with him).
It says in al-Mawsoo’ah al-Fiqhiyyah (28/91):
“The jurists are unanimously agreed that it is recommended to fast during the first eight days of Dhul-Hijjah, before the day of ‘Arafah. The Maalikis and Shaafa’is stated that it is Sunnah to fast on these days for the pilgrim too.”
It says in Nihaayat al-Muhtaaj (3/207):
“It is Sunnah to fast the eight days before the day of ‘Arafah , as is stated in al-Rawdah, and that applies equally to pilgrims and others, but it is not Sunnah for the pilgrim to fast on the day of ‘Arafah, rather it is recommended for him not to fast then, even if he is able to fast, following the example of the Messenger (peace and blessings of Allaah be upon him), and so that he will have more strength for du’aa’.”
And Allaah knows best.