The Prophet Muhammad (SAW) said “Visit the grave as often as possible, it will soften hearts and remind you of death.”
The purpose of visiting the graves is to remind us about our inevitable end and return to Allah(SWT) to account for our lives.
On entering the graveyard, its recommended to say Assalaamu ‘alaykum ahl al-diyaar min al-mu’mineen wa’l-Muslimeen, in sha Allaah bikum laahiqoon, as’al Allaaha lana wa lakum al-‘aafiyah which means “Peace be upon you O people of the dwellings, believers and Muslims, In sha Allaah we will join you, I ask Allaah to keep us and you safe and sound).”
When visiting the graveyard, it’s important to make dua (supplication) for the deceased and not to talk about worldly matters. Dua should be made facing the qibla, not the graves. Care should be taken not to walk on or disturb any of the graves.
For those who have passed away, it’s important to remember them in a good light and if one is not able to, then it’s better to remain silent.