שולחן ערוך, יורה דעה שמ״ג

Shulchan Arukh, Yoreh De'ah 343

מצות הלויית המת. ובו ב' סעיפים:
מת בעיר כל בני העיר אסורין במלאכה שכל הרואה מת ואינו מלווהו עד שיהא לו כל צרכו בר נידוי הוא ואם יש חבורות בעיר שכל אחת מתעסקת במתים ביומה מותר ביום שאינה יומה בד"א שלא בשעת הוצאתו אבל בשעת הוצאתו הכל בטלים כדלקמן:
[As long as there is] a dead person in town [awaiting burial] all the townspeople are forbidden [to engage] in work. And whosoever sees a corpse and does not attend to all its [burial] needs, is subject to be placed under a ban. However, if there are associations in town, each one of which attends to [the burial needs of] the dead on its [particular] day, it is permissible [for the others who are not required to attend to the burial needs, to engage in work] on the day which is not [appointed] for it [the association]. This applies only to the time when the [funeral] escort was not yet held, but during the [funeral] escort all must abstain from [work] as will be explained infra.
בכפר קטן אין שואלין שלום זה לזה כשהמת בעיר: הגה וכל שכן שאין שואלים בשלום כשיש מת על בית הקברות (כתבי מהר"ר אסרלין סימן כ"ה בשם ספר חסידים) אבל כשאין מת שם שואלין ברחוק ארבע אמות מן הקבר (בתוס' דאלפס פרק ג' דמ"ק והכל בו בשם הר"מ):
In a country town one must not extend a greeting of 'peace' to others whilst the corpse is in town. Gloss: So much the more that one must not extend a greeting of 'peace' to others when there is a corpse [awaiting burial] on the cemetery, but when there is no corpse there, one may extend a greeting of 'peace' to others at a distance of four cubits from the grave.

Ashlei Ravrevei: Shulchan Aruch Yoreh Deah, Lemberg, 1888 (Public Domain) · Code of Hebrew Law by Chaim N. Denburg, Montreal, 1955 (CC-BY) · 2 se'ifim