Reference: I’laam al-Mu’aasireen bi-Fataawa Ibn ‘Uthaymeen – Page 245
Question: Should one extend salutations upon the deceased in their graves from within the graveyard or from the street whilst passing by the graveyard?
Response: [Extending] the salutation upon the deceased in the graveyard is done from within the graveyard, i.e. upon entering the graveyard. As for passing by [the graveyard], then if the graveyard is fenced in, then salutations [upon the deceased] are not to be extended. And if it is not fenced in, then [in this case] some of the scholars have said if he passes [by the graveyard] then he should extend salutations so as to attain the reward [for doing so]; This is because [in doing so] he will be supplicating for his [muslim] brothers [and sisters therein], and thereby extending good to them – and in that there is reward and [much] good, in shaa.-Allaah.
السلام على أهل القبور
المرجع: إعلام المعاصرين بفتاوى ابن عثيمين – ص245
السؤال: هل يسلم على أهل القبور داخل المقبرة أم في الشارع عند المرور بالمقابر؟
الجواب: السلام على أهل المقابر يكون داخل المقبرة أي: إذا دخل المقبرة أما إذا مر بها فإن كانت المقبرة مسورة فإنه لا يسلم و إن لم تكن مسورة، فقد قال بعض العلماء: إذا مر فليسلم ليحصل على الأجر، لأنه سيدعو لإخوانه فيكون محسناً إليهم، و في ذلك أجر و خير إن شاء الله.