Praise be to Allah.
Fasting on the first eight days of Dhu’l-Hijjah is mustahabb for pilgrims and others, because the Prophet (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 fuqaha’ are unanimously agreed that it is mustahabb to fast during the first eight days of Dhu’l-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. End quote.
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 mustahabb for him not to fast then, even if he is able for it, 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’. End quote.
And Allaah knows best.