Question: Is the invocation of peace upon the dead to be uttered only upon entering the graveyard, or can it also be uttered when passing by [the graveyard]?
Response: It is as he (sal-Allaahu ‘alayhi wa sallam) said in the hadeeth when visiting the graveyard:
So the one passing by from outside [the graveyard] does not assume the ruling of the one inside [visiting the graveyard]. [That said] however, if he were to extend the invocation of peace upon the dead as he passed by [the graveyard], then that is fine, but we cannot apply the [same] ruling upon him as the one who is inside [the graveyard, visiting]. That is because the one inside has actually made the intention to visit [the graveyard], and as for the one passing by [the graveyard] – outside, has not made the intention to visit [the graveyard]. However, if he sought forgiveness [for the dead] and supplicated for them, then [all] that is good.