‘A'isha said that whenever it was her turn for God's messenger to spend the night with her he would go out towards the end of the night to al-Baqi' and say, “Peace be upon you, household of a people who are believers. What you were being promised will come to you tomorrow, you receiving it after some delay, and if God will we shall join you. O God, grant forgiveness to the inhabitants of Baqi' al- Gharqad.” (This is the full name of the cemetery at Medina. Baqi' properly means a place with tree roots, and gharqad is the name of a thorny type of tree. The name was retained even when all signs of trees were removed.)
Ibn 'Abbas said that when God's messenger passed by some graves in Medina he turned his face towards them and said, “Peace be upon you, inhabitants of the graves. God forgive us and you. You have gone before us and we are coming after.”
Tirmidhi transmitted it saying this is a hasan gharib tradition.
She said she asked God’s messenger what she should say, i.e. when visiting graves, and he told her to say, “Peace be upon the inhabitants of the abodes, believers and Muslims, and God show mercy to those of us who go before and those who go later. If God will we shall join you."
Buraida said that God's messenger used to teach them to say when they went out to the cemeteries, “Peace be upon you, inhabitants of the dwellings who are of the number of the believers and the Muslims. If God will, we shall join you. We ask God to grant us and you wellbeing.”