The Torah obligation of "Mipeneh Seba Takum" (Vayikra 19:32) requires one to stand in honor of the elderly. The Shulhan Aruch rules that this obligation refers to people aged seventy or above. If somebody of this age comes with four Amot of a person, the person is required to stand as an expression of respect under the elderly individual is no longer within four Amot.
Does this obligation apply while a person is in the middle of praying? If, for example, an elderly person passes by someone as he sits and recites Pesukeh De’zimra, Shema, or the Berachot before or after Shema, must the person rise in the middle of his prayer? Or, do we perhaps apply to this case the famous principle of "Osek Be’misva Patur Min Ha’misva," which means that a person currently involved in a Misva is exempt from other Misvot, such that he is exempt from the obligation to stand?
The Hid"a (Rav Haim Yosef David Azulai, 1724-1806) cites a responsum that he found in a written manuscript by a Rabbi who maintained that one does not stand to honor the elderly person in such a case. He claimed that it is inappropriate to give honor to a person at the expense of God’s honor, which would be infringed upon by disrupting one’s prayer service. According to Kabbalistic teaching, it is improper to make any interruption at all while praying, and therefore, according to this view, one should not rise in the middle of a prayer to give honor to an elderly person.
The Hid"a, however, disagrees with this ruling. He argues that since God Himself commanded us to give honor to the elderly, and thus doing so fulfills the divine will, there is no dishonor to God whatsoever by rising for an elderly person during Tefila. To the contrary, it displays loyalty to the Torah’s command. This was also the position of Rav Yosef Haim Sonenfeld (Israel, 1849-1932), who wrote, "Hashem, may He be blessed, who commanded us to recite Shema, also commanded us to stand in the presence of Torah scholars – and thus he is only doing that which he was commanded!" In his view, then, one does not dishonor God by standing during the prayer service to give honor to an elderly person as the Torah requires. This is, indeed, the ruling of Hacham Ovadia Yosef.
It should be noted that this situation occurs quite often in the synagogue. It is not uncommon in many congregations for elderly people to enter or leave during the prayer service, and it can certainly happen that an elderly person comes within four Amot of a person reciting Pesukeh De’zimra or Shema, for example. One should stand in honor of the elderly person in such a case, even though he is in the middle of praying.
Hacham Ovadia adds that during Birkat Ha’mazon, too, one should stand if an elderly person passes near him. Even though Birkat Ha’mazon has the status of the Amida with respect to interruptions, and thus one does not interrupt Birkat Ha’mazon even to respond to Kaddish or Kedusha, nevertheless, one should stand for an elderly person that passes near him during Birkat Ha’mazon. Halacha distinguishes in this regard between verbal and non-verbal interruptions, and standing does not constitute a Hefsek (forbidden interruption) during Birkat Ha’mazon.
Summary: One must stand when an elderly person – aged seventy or older – comes within four Amot of him, even if he is praying or reciting Birkat Ha’mazon.