The foundation of the entire discussion is that one who sees a deceased being taken for burial and does not escort him transgresses the prohibition of "he who mocks the poor blasphemes his Creator" (Berakhot 18a), a ruling that the Shulchan Arukh (Yoreh De'ah 361:3) codifies explicitly, adding that one must escort the deceased at minimum four cubits.
The Gemara establishes the governing principle: Torah study is interrupted for the escorting of the deceased, as Megillah 29a teaches — and illustrates with the practice of Rabbi Yehuda son of Rabbi Elai — but immediately qualifies this: the obligation applies only when there are not sufficient others already attending to the deceased's needs; when there are sufficient people, additional individuals need not interrupt their Torah study.
The Maharal explains the conceptual logic behind this qualification: the Maharal (Netivot Olam, Netiv HaTorah 1) reasons from the principle that Torah supersedes even other mitzvot when those mitzvot can be performed by others, but yields to a mitzva that cannot be performed by others — so the exemption from interrupting Torah study depends entirely on whether the deceased's honor can be sufficiently secured without one's participation.
The Shulchan Arukh (Yoreh De'ah 361:1) codifies a three-tiered hierarchy: for one who taught students, Torah study must be suspended no matter how large a crowd is already present; for one who read Scripture and studied Mishna but did not teach students, suspension is unnecessary if sixty myriads attend; for one who neither read nor studied, suspension is unnecessary provided there are at least ten others attending — with a gloss from the Rema noting that in the present era, virtually every Jew qualifies as one who has read or studied, so that the lenient threshold for the unlearned applies to almost no one.
The Beit Yosef traces the sources of these rulings and records that the Beit Yosef (Yoreh De'ah 361) cites the Behag, Rav Natronai Gaon, the Ramban, the Rosh, Tosafot, and the Ritva — with the Ritva further transmitting the Sefer HaMitzvot of the Smag's position that in the present era one presumes every Jew has learned at least Scripture or Mishna, so that the unlearned category is effectively empty.
The Arukh HaShulchan sharpens the practical ruling: the Arukh HaShulchan (Yoreh De'ah 361) holds that even for a simple person with no learning, where there are sufficient attendants, one engaged in Torah study need not interrupt — but crucially, he specifies that where chevra kadisha groups exist in the city, rotating by day, those whose day of service it is not are explicitly permitted both in labor and in Torah study; and even where no such groups exist, while the entire city is forbidden to work, they are still not required to interrupt Torah study except at the actual moment of the procession in order to escort the deceased.
Undergirding the entire obligation is the Torah's positive command of burial in Devarim 21:23, which Sanhedrin 46b derives from the doubled verb "kavor tikberennu" as a prohibition against leaving a deceased overnight, and which the Sefer HaChinukh (Mitzvah 537) extends to the burial of all Jewish dead — noting that a deceased with no one to attend to his burial is called a "met mitzva" precisely because the obligation devolves upon everyone.
The Rambam frames care for the deceased as an act of chesed and assigns it priority in cases of conflict: the Rambam (Hilkhot Avel 14:8) rules that when one faces a deceased and a bride simultaneously, he sets aside the bride and attends to the deceased, deriving from the verse in Kohelet that the heart of the wise is drawn to the house of mourning — and the Rambam (Hilkhot Avel 14:1) catalogues the acts of chesed involved: bringing out the deceased, carrying on the shoulder, walking before him, eulogizing, digging, and burying.