Visiting المدينة and praying in النبي's المسجد is highly مستحب and is one of the most virtuous acts a Muslim can perform. However, it is essential to understand that visiting المدينة is not part of the الحج rites — it is a separate, independent act of worship. A الحاج may visit المدينة before الحج, after الحج, or even at a completely different time. Both timings are equally valid and there is no scholarly preference for one over the other.
الشيخ ابن باز stated that the purpose of visiting المدينة is to pray in النبي's المسجد, where one الصلاة equals one thousand الصلوات in other مسجدs (except المسجد الحرام). The الحاج should also send salam upon النبي 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 المدينة is for the sake of praying in the مسجد, not 'visiting the grave' as a الحج destination — this is an important theological distinction.
الشيخ ابن عثيمين confirmed that there is no connection between الحج and visiting المدينة in terms of Islamic law. Some الحجاج mistakenly believe that visiting المدينة is part of الحج or that their الحج is incomplete without it. This is incorrect. الحج is complete with its own rites performed in مكة, عرفة, مزدلفة, and منى. Visiting المدينة is a separate recommendation that can be done at any time. He advised الحجاج to plan their المدينة visit based on practical considerations — flight routes, hotel availability, and group schedule — rather than believing one timing is religiously superior.