It is written at BaMidbar 16:27 וַיֵּעָלוּ, מֵעַל מִשְׁכַּן-קֹרַח דָּתָן וַאֲבִירָם--מִסָּבִיב; וְדָתָן וַאֲבִירָם יָצְאוּ נִצָּבִים, פֶּתַח אָהֳלֵיהֶם, וּנְשֵׁיהֶם וּבְנֵיהֶם, וְטַפָּם (here it appears the טַפָּם died also because of the sins of their fathers); how can we reconcile this with Devarim 24:16 לֹא-יוּמְתוּ אָבוֹת עַל-בָּנִים, וּבָנִים לֹא-יוּמְתוּ עַל-אָבוֹת: אִישׁ בְּחֶטְאוֹ, יוּמָתו?
The Midrash Tanhuma (ed. Buber: Parashat Korah 6) notes that this was abnormal as normally children are not punished:
אמר ר' ברכיה כמה קשה המחלוקת שב"ד של מעלה אינן קונסין אלא מבן עשרים שנה, וב"ד של מטה מבן שלש עשרה שנה, ומחלוקתו של קרח תינוקות בני יומן נשרפו, ונבלעו בשאול תחתית, דכתיב ונשיהם ובניהם וטפם
Rabbenu Bahaya asks this as a question (Parashat Korah 16:29): what did the children do? He answers that it can only be understood kabbalistcally.
Rambam writes in Hilkhot Teshuva (6:1), however, that Deuteronomy (24:16) only means that adults (איש) are punished on their own merits, but a child may be punished for his parents' sins:
יש חטא שהדין נותן שנפרעים ממנו על חטאו בעולם הזה בגופו או בממונו או בבניו הקטנים שבניו של אדם הקטנים שאין בהם דעת ולא הגיעו לכלל מצות כקניינו הן וכתיב איש בחטאו ימות עד שיעשה איש
Rambam's position is supported by the Sifrei Zuta to Ruth (ed Buber; 1:5) which states that until a boy is 13 he is punished for his fathers' sins; after that he becomes included in Deut. (24:16) and is only punished for his own sins:
אמר ר' חייא בר אבא עד שלש עשרה שנה הבן לוקה בעון האב, מכאן ואילך איש בחטאו ימות
Alternatively, R. Yissakhar Teichtal suggests in Mishneh Sakhir (Parashat Korah s.v. V'datan Vaaviram) that in reality these children were old enough to have been involved in the dispute themselves. Thus, they were punished for their own sin; not that of their parents:
ועיי"ש פרש"י בשם המדרש. ולי נראה עפ"י פשוט עפ"י המעשה דגם הנשים בכלל המחלוקת וגם הבנים והטף, וק"ל
The fact that the children of Dasan and Aviram stayed with their father was enough to include them in the sin. The children of Korach did teshuvah and moved away from their father so they were saved. In fact Hashem replies to the entreaties of Moshe.
"Speak to the congregation saying, 'Withdraw from the dwelling of Korah, Dathan and Abiram.'"
This leads to:
So they withdrew from around the dwelling of Korah, Dathan, and Abiram, and Dathan and Abiram went out standing upright at the entrance of their tents together with their wives, their children, and their infants.
This implies that the children of Korach did withdraw from around their fathers tent and did teshuvah.
Note that the infants are in the position of being killed by their parents like someone refusing to leave a burning building or evacuate during a flood. and not allowing the children to be saved. The adult children of Dasan and Aviram could have left with the infants.
As Rashi says on that pasuk.
their wives, their children, and their infants: Come and see the severity of dispute. The earthly courts do not punish until [an accused] has two [pubic] hairs, and the heavenly court does not punish until one reaches the age of twenty, but here even nursing babes were punished. - [Midrash Tanchuma Korach 3]
The implication is that even those who could not of their own free will leave, were caught up in the punishment, even though they had not done anything themselves.