Burayda bin Husayb reported,

The Messenger of Allah ﷺ used to teach them what to say when they went out to the graveyards. Their spokesman would say (in Abu Bakr's narration), "Peace be upon the inhabitants of these dwellings," and (in Zuhayr's narration), "Peace be upon you, inhabitants of these dwellings, from among the believers and the Muslims. Allah willing, we shall join you. I ask Allah for well-being for us and for you."

Azami 11113

Sahih

عن بريدة بن الحصيب قال

كان رسول الله ﷺ يعلمهم إذا خرجوا إلى المقابر، فكان قائلهم يقول ( في رواية أبي بكر): السلام على أهل الديار، (وفي رواية زهير): السلام عليكم أهل الديار من المؤمنين والمسلمين، وإنا إن شاء الله للاحقون، أسأل الله لنا ولكم العافية.

الأعظمي 11113صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Supplications, remembrances, and prayer upon the chosen Prophet ﷺ
Chapter
Supplications for illness and funerals, and what relates to them
Section
Supplication for visiting graves
Numbering
Jami al-Kamil 11113 (2nd edition)
Azami 11113