Some commentators on Rashi (e.g. Nachalas Yaakov and Maskil L’Dovid) suggest that being part of a dispute permeates a person so deeply that even the children were affected by it (see Gur Aryeh), and they therefore had to be eliminated along with the other disputants. A comparison is made to the “ben sorer u’moreh,” the rebellious son who is put to death so that he dies without sin rather than allowing him to sin and be punished for it. However, the “ben sorer u’moreh” was not an infant; can newborn infants be so affected by a dispute their parents are involved in that their lives are not worth being spared? Besides, it only pushes the question back one step; what did the souls of these infants do wrong to be born into families involved in a dispute, which in turn caused them to be included in the punishment?
Rabbeinu Bachye (17:29), in order to explain how innocent children were swallowed by the earth, as well as why Moshe didn’t pray for the adult sinners after having prayed for other sinners (see Sh’mos 32:11 and 32:31-32, Bamidbar 11:2 and 14:13-19), tells us that those involved with Korach’s rebellion were the reincarnated souls of the wicked men of Sodom, who had also been the reincarnated souls of those who tried to build the Tower of Babel (B’reishis 11:3-4). The men who joined Korach were described as “anshei shem,” men who were well-known (Bamidbar 16:2), and the purpose of building the Tower was to “become well-known” (“v’na’aseh lanu shem”). Similarly, the men of Sodom who surrounded Lot’s house were blinded so that they couldn’t break down his door (B’reishis 19:11), and Dasan and Aviram told Moshe that even if he blinded them they wouldn’t meet with him (Bamidbar 16:14). Rabbeinu Bachye says that the Torah uses these literary devices (and others) to indicate that this was the third major sin these souls were involved with; although usually a soul will get it right by its third chance (referencing Koheles 4:12), in this case they didn’t, so Moshe knew it was futile to pray for them. [Rashi (16:4) quotes Chazal, who gave a different reason why Moshe didn’t pray on behalf of these sinners; for my thoughts on this approach, see www.aishdas.org/ta/5766/korach.pdf.]
Rabbeinu Bachye says that this answers his other question too, how these children can suffer if only their parents sinned, but I’m not sure how. Since the infants were too small to have sinned with Korach, their souls only had two chances, not three! In his introduction to Sefer Iyov, the Ramban gives several reasons why seeing the righteous suffer does not contradict G-d being completely just. One of them is that the righteous who suffer could be the reincarnated souls of people who weren’t completely righteous, but didn’t receive the punishment for what they had done in their previous life (while they lived it). Therefore, their souls are sent back again, during which time they receive the punishment for what they had done in the previous life, even if nothing they did in their current life warrants such a punishment. It is therefore possible that the souls of these infants were being punished for their participation in those previous sins, even if they couldn’t be held accountable for this one. (If so, they should have to be given a third chance in still another lifetime.) Although this answers Rabbeinu Bachye’s question while being consistent with his reincarnation angle (and Rabbeinu Bachye often quotes, at length, word for word, the Ramban’s commentary), he does not add this additional piece to the puzzle, making it difficult to say that this is what he meant.
The question of how children can suffer at all, let alone be punished along with Korach’s followers, shouldn’t need a reincarnation background, or the severity of disputes, in order to be explained. As I have discussed on numerous occasions (e.g. http://rabbidmk.wordpress.com/2013/05/02/bechukosai-5773/), not everyone is worthy of divine intervention. Children, who have not yet had a chance to create a strong enough connection to G-d to merit His protection in their own right, are therefore subject to the consequences of the actions of others. (This actually applies to most people, even adults, see S’fornu on Vayikra 13:47, but at least adults have the opportunity to create a strong enough connection with G-d to be protected by Him.) When G-d told Moshe that He was about to punish Korach and his followers, He told Moshe to have everyone else move away so that they wouldn’t suffer the same consequences (Bamidbar 16:26); if the adults who weren’t part of Korach’s group had to move away in order not to be swallowed alive by the earth, how could we expect the children who were still at “ground zero” not to be swallowed by it? Why would we expect children, who do not merit divine protection in their own right, to be saved from a dangerous situation just because they’re children?
When lamenting the destruction of Yerushalayim, the prophet lists some of the consequences, including that “her young ones were taken captive” (Eichah 1:5). The Nesivos (Palgay Mayim) explains that children, who are innocent, being taken captive proves that G-d was no longer protecting Israel, as otherwise He wouldn’t have let those without sin suffer. The Nesivos is referring to protection on a national level, as when we, as a nation, are deserving of His protection, individuals don’t need to be worthy of it in their own right. In the desert, with G-d’s presence residing in the Mishkan, we did have divine protection on a national level, as evidenced by the “clouds of glory” (see http://rabbidmk.wordpress.com/2013/06/20/parashas-balak-5773/), so the children should have been protected too. The question of why they weren’t (i.e. how they suffered) would seem to be based on the fact that at this point in time the nation was being protected by G-d, so unless a punishment is purposely directed at a sinner (and children can’t be considered sinners), they shouldn’t have suffered.
Since the “starting point” for children (including infants) is that they are not protected (and could therefore experience suffering even without having sinned), and in the desert they should have been protected because of the “umbrella protection” that the nation as a whole was experiencing, if there was a hole in that “umbrella,” the national protection would not cover everyone. “Come and see how harsh dispute is, for human courts do not punish a sinner until he is 13, and the heavenly court until he is 20, and here even those who were still nursing were destroyed.” Not because these children were being held accountable for actions they had no control over, but because the dispute had created a “hole” in the divine national protection, with G-d not protecting those involved in the dispute. It was for this reason that the rest of the nation was warned to move away, as anyone nearby wouldn’t be protected either. And since these children were there when the earth opened up beneath the sinners, they were swallowed up with them.
There is one more point to add. The Midrashim that Rashi paraphrased do not start with Rav B’rechya’s statement about how severe disputes are. Rather, they first say that whoever assists in a dispute will have his memory destroyed. The implication is that he will lose his progeny (thereby leaving no legacy), after which Rav B’rechya’s adds that from here we see how severe disputes are, as even infants are destroyed. They are destroyed as part of the punishment of the parents, which operates even (or perhaps especially) when the nation is being divinely protected, since infants and children do not merit specific protection of their own.