Tractate Ketubot 17a: Our Rabbis taught: One interrupts the study of the Torah for the sake of a funeral procession and the leading of the bride [under the bridal canopy]. They tell of R. Judah b. Ila'i that he interrupted the study of the Torah for the sake of a funeral procession and the leading of the bride [under the bridal canopy]. This applies only when there are not sufficient people at the funeral procession, but if there are sufficient people one does not interrupt [the study of the Torah]. And how many are sufficient? R. Samuel the son of Ini said in the name of Rab: Twelve thousand men and six thousand trumpets. And some say: Twelve thousand men and among them six thousand trumpets. 'Ulla said: For instance when people form a line from the city-gate to the burial place. R. Shesheth, and some say R. Johanan said: Its taking away is like its giving. As its giving was in [the presence of] sixty myriads [of people], so [has] its taking away [to be] in [the presence of] sixty myriads [of people]. And this is the case only with regard to one who read [the Bible] and studied [the Mishnah.] But for one who taught [others] there is no limit.
And so rules the Rambam (Maimonides) Laws of Avel 14, 9-11:
We nullify Torah study for a funeral and for a wedding. When does the above apply? When there are not enough people to care for a corpse. If there are enough people to care for it, Torah study should not nullified. Whoever does not occupy himself with Torah study is obligated to occupy himself with the corpse. If there is one corpse in a city, all the inhabitants of the city are forbidden to perform work until they bury him. If there is a person responsible for tending to the needs of funeral, the others are permitted.
When a Torah scholar dies, unless there are 600,000 to accompany him, we nullify Torah study for his funeral. If there are 600,000, we do not nullify Torah study. If he would also teach others, there is no limit. Instead, we nullify everyone from their ordinary activity for his funeral.
HaGaon Rav Chaim Pinchas Scheinberg ZT"L told me several years ago that we don't keep this Halachah nowadays due to "A time to do for the Lord; they have made void Your Torah" (Psalms 119, 126. Berachot 54a). If Torah study will be nullified in order to have 600,000 at the funeral of every Torah scholar, and all will nullify Torah to attend the funeral of one who taught Torah to others, what will ever happen to Torah?! Who will ever have time for Torah?!
(He told me this in context of a question I asked him regarding the Mitzvah of "You shall rise before the aged" (Lev. 19:32). Is one obligated to rise to his full height before every old man while learning in the Beit Midrash at the Mir Yeshiva in Jerusalem, where there are many old people who come during the learning sessions to collect money for charity, since it is ruled in the Shulchan Aruch (Yoreh Deah 244, 11) that even while one is occupied in Torah study he is obligated to rise before an old man, or is it enough if one shows respect by rising slightly which demonstrates that he wanted to honor him by rising to his full height, and perhaps we can rely on the assumption that they forgo their honor. I pointed out sections 6-7 which note that even in cases where one is exempt from rising to his full height nevertheless he should show respect as mentioned above (and as the story of Rav Papa who was serving drink at the wedding of Abba Mar, his son; etc. Kiddushin 32b and in Rashi D"H Hiddur). [Which is contrary to the Mishpetei Shmuel quoted by the Beit Lechem Yehudah on the Shulchan Aruch above 242, 32. that a Rabbi who relinquishes his honor, his honor is relinquished only if he said so expressly, but silence does not count]. Rav Scheinberg replied to me that indeed one can rely on that. He told me that he was once asked a similar question regarding people whose learning place was next to Shtiblach – "small synagogues" which had many and frequent Minyanim (prayer services), and if they would interrupt their learning in order to answer every Kaddish and Kedushah that would completely destroy their studies, so he responded to them that "A time to do for the Lord; they have made void Your Torah", and compared it to the law of 600,000 people at the funeral of a Torah scholar as mentioned above).
Regarding praying with a Minyan at the mourner's house where there are already scores of people attending:
As far as the actual issue of prayer at the house of mourning, the custom is to pray there with a Minyan of ten men, especially if this is the place where the deceased died, for the benefit of the deceased's soul and for the benefit of the mourners. This is part of the Mitzvah of comforting the mourner.
)Shulchan Aruch and Rema Yoreh Deah 376, 3. and 384, 3. Gesher Hachaim 20,3a. Penei Baruch 10, 18 and in notes. Nitei Gavriel vol. 1, 91 and in sources (.
It seems that for this, one does not need more than a small Minyan, and as far as the other people it is better that they pray in their usual place in the synagogue because of the importance of prayer in a fixed place (see Berachot 6b: Whosoever has a fixed place for his prayer has the God of Abraham as his helper etc. and on page 7b; If a man has a fixed place for his prayer, his enemies succumb to him. and in Shulchan Aruch 90, 19. and in Mishnah Berurah) and because of "BeRov Am Hadrat Melech", "A multitude of people is a King's glory" (Mishlei 14:28). And because of the sanctity of a synagogue (Shulchan Aruch 90, 9,11,18. and in Mishnah Berurah 27, 28, 55 ).
Rabbeinu Yonah writes (in his sermons and commentaries on the Torah, end of Terumah) about the importance of prayer in synagogues and in Batei Midrashot which are a "miniature sanctuary". If it was a place where they learned Halachah, it is preferable to pray there. They said (Berachot 8a.) The Holy One, blessed be He, has nothing in this world but the four cubits of Halachah alone. And furthermore said R. Ammi and R. Assi (ibid), that even though they had thirteen Synagogues in Tiberias, they prayed only between the pillars where they used to study. Therefore one should not neglect prayer in his regular synagogue, even for another synagogue, for the sake of consistency of the place of prayer, and even more so in houses of mourning and houses of canopies and circumcisions.