Visiting the graves at Baqi al-Gharqad cemetery in المدينة is a مستحب السنة for men. النبي (صلى الله عليه وسلم) used to visit Baqi frequently and would make الدعاء for those buried there. Many of the greatest companions are buried at Baqi, including Uthman ibn Affan, the wives of النبي (except Khadijah), and many others. Visiting their graves is an act of remembrance and a source of reflection.
الشيخ ابن باز stated that the visitor should greet the deceased with the السنة greeting: 'Peace be upon you, O people of the abode, from among the believers and the Muslims. May Allah have mercy on those who have gone ahead and those who will follow. We ask Allah for well-being for us and for you.' The visitor then makes دعاء for the deceased and reflects on death and the Hereafter. This is the purpose of visiting graves — remembrance of death and الدعاء for the dead.
الشيخ ابن باز also warned against innovations that some people practice at graves: wiping or touching the graves, asking the deceased for intercession or help, placing flowers or cloth on the graves, sitting on the graves, praying toward the graves, or making the visit a formal ritual with specific timings. All of these have no basis in the السنة and are prohibited. The visit should be simple — greeting, الدعاء, and reflection. Women visiting graves is a matter of scholarly discussion, with some scholars permitting it if done properly and without excessive wailing.