Hazrat Ibn Umar R.A relates that Rasulullah Sal’am said: ‘Whosoever visits me after my death is like he who had visited me during my life.’ (Tabraani-Dar-Qutni)
It is stated in a Hadith in ‘Mishkaat’ that; ‘The person who performs Haj then visits my grave, is like he who visited me during my lifetime’. The term ‘is like he’ does not mean that he becomes a Sahaabi, but because the Ambiyaa are alive in their graves, he is like that person who comes to Rasulullah Sal’am during his life and greets him from the outside of his house. In this hadith it is stated that he visits me after Haj. The ulama have different views about the visit to Madina Munawwarah; whether it should be before going to Mecca or after. Hazrat Ibn Hajar Rah has written that the opinion of most Masha’ikh is that Haj should be performed first. The more acceptable view is that if there is sufficient time before Haj, then the Ziyaarat should be made with comfort and ease before Haj, thereafter Haj could be performed without haste. It is possible that for some reason or the other after Haj the visit to Madina has to be called off. If the time before Haj is not sufficient for a Ziyaarat then it should be preformed after Haj.
Hazrat Mullah Ali Qari Rah has written that if the Haj is a fardh, then Haj should be made first, provided Madina Munawwarah is not on the route. If Madina is on the way then it will be treacherous to continue without performing Ziyaarat. If it is a nafl Haj then it is optional to visit Madina before or after Haj. It could be better in this instance also to perform Haj, first, by which one is made paak (sins are forgiven) before visiting the paak tomb of Rasulullah Sal’am.