Visiting his grave is by consensus a sunnah; some of the scholars even said it is an obligation (wajib). This is due to several religious proofs. One of them is the hadith:
{ من زارَ قبري وَجَبَتْ لَهُ شَفَاعَتي }
رواهُ الدّارَقُطْنيُّ وقَوَّاهُ الحافِظُ السُّبكي
It means: “The one who visits my grave has earned my intercession.” This hadith is narrated by ad- Daraqutniyy and classified as “hasan for other than itself” (hasan lighayrih).
The false claim of Ibn Taymiyah that it is forbidden for one to travel with the purpose of visiting the grave of the prophet, is a matter that does not comply with the rules of the religion. Ibn Taymiyah misinterpreted the hadith of the Prophet, narrated by al-Bukhariyy:
لا تُشدُّ الرحال إلا إلى ثلاثة مساجد: مسجدي هذا، ومسجد الحرام، ومسجد الأقصى
Due to his ill understanding of this hadith, Ibn Taymiyah claimed that it means that one is not allowed to travel except to those three mosques: the Aqsa Mosque, the Prophet’s Mosque, and the Haram Mosque (in Makkah). Based on that, he ruled that it is forbidden for one to travel to visit the grave of the Prophet. Ibn Taymiyah’s claim breached the consensus of all the scholars who preceded him.
The correct meaning of the hadith is: “One ought not travel to a mosque with the purpose of praying in it, except if one was travelling to one of these three mosques: the Aqsa Mosque, the Prophet’s Mosque, and the Haram Mosque in Makkah.” This is so because the reward of praying is multiplied in these three mosques compared to the reward of praying in other mosques. This is a merit specific for those three mosques and not for any other mosque.
What sheds clear light on the meaning of the hadith is another narration of the same hadith that explains the aforementioned one. Imam Ahmad narrated that the Prophet explicitly said: “One should not drive the animals in travelling towards a mosque with the purpose of praying in it, with the exception of the three mosques, the Aqsa Mosque, the Prophet’s Mosque, and the Haram Mosque. This narration is very explicit in clarifying the meaning of the aforementioned hadith, and it is in compliance with the consensus of the nation, contrary to the false claim of Ibn Taymiyah.
Moreover the Prophet, sallallahu ^alayhi wa sallam, said: “Prophet ^Isa (Jesus) shall come down from the (second) heaven to Earth and rule Earth justly. Moreover, he will take a route between two mountains to make Hajj or ^Umrah and come to my grave. He will say: As-Salamu^alaykum to me and I will respond to him.” This hadith is narrated by al-Hakim and Abu Dawudat–Tayalisiyy. Al Hakim, hafidh adh-Dhahabiyy, and others classified it as a sahih hadith.
This hadith proves that travelling to visit the grave of the Prophet, sallallahu ^alayhi wa sallam, is not sinful. On the contrary, this is what Prophet ^Isa will do. By this, it is very clear that no weight should be given to the deviated claim of Ibn Taymiyah.
Note: When one gets into the Prophet’s Mosque, one makes two optional rak^ahs to salute the Mosque. Then, one stands politely facing the grave of the Prophet about four (4) cubits away from the wall, lowering one’s gaze and filling one’s heart with love and respect for the Prophet. Then, one says with a medium voice: As-Salamu^alayka ya Rasulallah; as-salamu^alayka ya Nabiyyallah, and the like. Then, one makes as–salah ^alan-Nabiyy. Afterwards, one goes about one cubit to the right and says as-salamu ^alayka ya Aba Bakrinis–Siddiq, then one more cubit to the right and says as-salamu ^alayka ya ^Umaral-Faruq. Then one goes to where one first stood and makes du^a’ asking Allah by the Prophet. One faces the Qiblah and makes du^a’ for oneself and for whomever one wishes. If anyone requested of one to convey one’s salam to the Prophet, one says: O Prophet of Allah, so and so gives you salam.
Source: http://www.myot.org.au/index.php?option=com_content&view=article&id=211:visiting-the-prophets-grave-is-sunna&catid=58:visiting-the-prophets-grave&Itemid=220