It is a known matter that one who is engaged in a mitzvah is exempt from a mitzvah. Therefore, the bearers of the casket, and their replacements, and the replacements of their replacements—since there is no strength to carry the entire way and therefore they switch from these to those—whether those who are before the casket or those who are after it, since the casket has need of them, meaning that these carry and those rest, these rest and those carry, and so on continually until the casket reaches the cemetery—all of them are exempt from the recitation of Shema, and from prayer, and from all the mitzvot. However, the rest of those escorting who do not carry the casket are obligated. And even though escorting the deceased is also a mitzvah, nevertheless, there is no fixed measure for this, and they escort for four amot and go, and recite Shema and pray. And it has already been explained in Orach Chaim siman 72. And it is simple that if there are enough for the carrying of the casket who will carry it from those who have already prayed—the others should go to pray even though they desire to carry the casket.
דבר ידוע שהעוסק במצוה – פטור מן המצוה. ולכן נושאי המיטה, וחלופיהן, וחלופי חלופיהן, לפי שאין כוח לשאת כל הדרך ולכן מחליפין מאלו לאלו, בין אותם שהם לפני המיטה ובין אותם שלאחריה, מאחר שיש למיטה צורך בהם, כלומר שאלו נושאים ואלו נחים, אלו נחים ואלו נושאים, וכן לעולם עד שתגיע המיטה לבית הקברות – כולם פטורים מקריאת שמע ומתפילה ומכל המצות. אבל שארי המלוין שאין נושאין את המיטה – חייבים. ואף על גב דגם הלוויית המת מצוה היא, מכל מקום הא אין שיעור לזה, ומלוים ארבע אמות והולכין, וקורין קריאת שמע ומתפללין. וכבר נתבאר באורח חיים סימן ע"ב. ופשוט הוא דאם יש די בנשיאת המיטה שישאוהו אותם שכבר התפללו – ילכו האחרים להתפלל אף שרצונם לשאת המיטה.