Visiting the dead (that is, the graves) is prescribed, and the visitor should stand facing the qiblah.
➊ It is narrated from Buraydah (may Allah be pleased with him) that the Messenger of Allah ﷺ said:
قد كنت نهيتـكـم عـن زيارة القبور فقد أذن لمحمد فى زيارة قبر أمه فزوروها فإنها تذكر الآخرة
“Indeed, I had forbidden you from visiting graves, but Muhammad ﷺ has now been given permission to visit the grave of his mother, so you too should visit graves. Surely they remind one of the Hereafter.”
➋ In one narration the words are:
فمن أراد أن يزور فليزر ولا تقولوا هجرا
“Whoever intends to visit (the graves) should visit, but do not say anything false (there).”
➌ It is narrated from Abu Sa’id al-Khudri (may Allah be pleased with him) that [he said], visit the graves:
فإن فيها عبرة
“For indeed, in them there is a lesson.”
(The majority of scholars): Visiting graves is recommended.
(Ibn Hazm, may Allah have mercy on him): Visiting graves is obligatory, even if it is done only once in a lifetime.
In one hadith it is stated:
فجلس النبى صلى الله عليه وسلم مستقبل القبلة وجلسنا معه
“The Prophet ﷺ sat facing the qiblah, and we sat with him as well.”
Because of this hadith, this act is recommended, not necessary.