Mishkat al-Masabih 1764
وَعَنْ بُرَيْدَةَ قَالَ: كَانَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ يُعَلِّمُهُمْ إِذَا خَرَجُوا إِلَى الْمَقَابِرِ: «السَّلَامُ عَلَيْكُمْ أَهْلَ الدِّيَارِ مِنَ الْمُؤْمِنِينَ وَالْمُسْلِمِينَ وَإِنَّا إِنْ شَاءَ اللَّهُ بِكُمْ لَلَاحِقُونَ نَسْأَلُ اللَّهَ لَنَا وَلَكُمُ الْعَافِيَةَ» . رَوَاهُ مُسْلِمٌ
From Buraydah, who said: The Messenger of Allah ﷺ used to teach them, when they went out to the graveyards, [to say]: "Peace be upon you, O inhabitants of the dwellings, of the believers and the Muslims, and we, if Allah wills, will be joining you. We ask Allah for well-being for us and for you." Reported by Muslim.