(Numbers 16:1:) AND DATHAN AND ABIRAM. From here they said: Woe to the wicked one, woe to his neighbor; good to the righteous one, good to his neighbor. Dathan and Abiram, who were neighbors to Korah, who was settled to the south, as it is written (Numbers 3:29), THE FAMILIES OF THE SONS OF KOHATH SHALL ENCAMP <on the side of the Tabernacle southward>. The standard of Reuben was near to them, [as it is said] (Numbers 2:10), THE STANDARD OF THE CAMP OF REUBEN SHALL BE SOUTHWARD. But the standard of Judah was in the east, and Issachar and Zebulun were with him, [as it is said] (Numbers 2:3), AND THOSE ENCAMPING EASTWARD TOWARD THE SUNRISE SHALL BE THE STANDARD OF THE CAMP OF JUDAH. And near to them were Moses, Aaron, and his sons, [as it is said (Numbers 3:38), AND THOSE ENCAMPING BEFORE THE TABERNACLE EASTWARD, BEFORE THE TENT OF MEETING TOWARD THE SUNRISE, WERE MOSES AND AARON AND HIS SONS.] Because these were near to the Torah, they therefore merited to be sons of the Torah, as it is written (Psalms 60:9), JUDAH IS MY LAWGIVER; [and it is written] (1 Chronicles 12:33), AND OF THE SONS OF ISSACHAR, THOSE HAVING UNDERSTANDING OF THE TIMES; [and it is written] (Judges 5:14), AND OUT OF ZEBULUN THOSE WHO WIELD THE SCRIBE'S PEN. But Dathan and Abiram, who were neighbors to Korah, a master of dissension, were stricken and perished from the world.
Why Dathan and Abiram Perished as Korah's Neighbors
Midrash Tanchuma Buber, Korach 8:1
ודתן ואבירם (במדבר טז א). מיכאן אמרו אוי לרשע אוי לשכנו, טוב לצדיק טוב לשכנו, דתן ואבירם, שהיו שכנים לקרח, שהיה שרוי בדרום, דכתיב משפחות בני קהת יחנו וגו' (שם ג כט), דגלו של ראובן סמוך להם, [שנאמר] דגל מחנה ראובן תימנה (שם ב י), אבל דגל של יהודה היה במזרח, וישככשר וזבולון עמו, [שנאמר] והחונים קדמה מזרחה דגל מחנה יהודה (שם שם ג), וסמוכין להן משה אהרן ובניו, [שנאמר והחונים לפני המשכן קדמה לפני אהל מועד מזרחה משה ואהרן ובניו] (שם ג לח), לפי שהיו אלו סמוכין לתורה, לכך זכו להיות בני תורה, דכתיב יהודה מחוקקי (תהלים ס ט), [וכתיב] ומבני ישככר יודעי בינה לעתים (דה" יב לב), [וכתיב] ומזבולון מושכים בשבט סופר (שופטים ה יד), ודתן ואבירם שהיו שכנים לקרח בעל מחלוקת, לקו ואבדו מן העולם.