Travelling in order to visit the Mosque of Allaahs Messenger (sallallaahu alaihi wa sallam), not His Grave.
Question:
What is the ruling on visiting the grave of the Prophet (sallallaahu alaihi wa sallam) and the graves of others among the Awliya, the righteous and so on?
Answer:
It is not permissible to travel with the intention of visiting the grave of the Prophet (sallallaahu alaihi wa sallam), nor the grave of any other person, according to the most correct of two opinions given by the scholars, based upon the saying of the Prophet (sallallaahu alaihi wa sallam):Do not saddle up your riding beasts except to (visit) three mosques: The Sacred Mosque (in Makkah), this Mosque of mine, and the Mosque of Al-Aqsa What is lawful for the one who wishes to visit the grave of the Prophet (sallallaahu alaihi wa sallam), but lives far away from Madinah, is to make his intention to visit the Prophets Mosque, which includes visiting the graves of the Prophet (sallallaahu alaihi wa sallam) and those of Abu Bakr and Umar and the martyrs and those of the people buried in Al-Baqi, may Allaah be pleased with them. Should he make his intention to do both, it would be permissible, since it is allowed to perform one as a subordinate action even though it is not allowed to perform it as a separate action. As for the intention only to visit the grave, it is not permissible when it involves undertaking a journey to do so. However, if one lives near the Mosque and visiting it does not require one to embark on a journey and cannot be considered travelling, then there is no objection to that, because visiting his grave and those of his two Companions - without travel - is a Sunnah and a way of drawing closer to Allaah. Likewise visiting the graves of the martyrs and those of the people in Al-Baqi, or the graves of the Muslims in any place, is a Sunnah and a way of drawing closer to Allaah. But this is without embarking on a journey, based upon the saying of the Prophet (sallallaahu alaihi wa sallam): Visit the graves, for they will remind you of the Hereafter. And he (sallallaahu alaihi wa sallam) used to teach his Companions, may Allaah be pleased with them, to say, when they visited the graves: Peace of Allaah be upon you, O people of the graves, from the believers and the Muslims. And, Allaah Willing, we shall follow you. We ask Allaah for well-being for us and for you.
Source:
Shaykh `Abdul-`Azeez Bin Baz
Fatawa Islamiyah Vol. 1 Page 83