Visiting Madinah and praying in Nabi's Masjid is highly sunnah and is one of the most virtuous acts a Muslim can perform. However, it is essential to understand that visiting Madinah is not part of the Haji rites — it is a separate, independent act of worship. A jamaah haji may visit Madinah before Haji, after Haji, or even at a completely different time. Both timings are equally valid and there is no scholarly preference for one over the other.
Sheikh Ibn Baz stated that the purpose of visiting Madinah is to pray in Nabi's Masjid, where one shalat equals one thousand shalat in other masjids (except Masjidil Haram). The jamaah haji should also send salam upon Nabi and his two companions, pray in the Rawdah if possible, and visit Baqi cemetery and the graves of the Uhud martyrs. He emphasized that the trip to Madinah is for the sake of praying in the masjid, not 'visiting the grave' as a ibadah haji destination — this is an important theological distinction.
Sheikh Ibn Uthaymeen confirmed that there is no connection between Haji and visiting Madinah in terms of Islamic law. Some jamaah haji mistakenly believe that visiting Madinah is part of Haji or that their Haji is incomplete without it. This is incorrect. Haji is complete with its own rites performed in Mekkah, Arafah, Muzdalifah, and Mina. Visiting Madinah is a separate recommendation that can be done at any time. He advised jamaah haji to plan their Madinah visit based on practical considerations — flight routes, hotel availability, and group schedule — rather than believing one timing is religiously superior.