In the Kurukshetra war, the Pandava side represented Dharma, and the Kaurava side adharma.Then, why numerous warriors in the Pandavas' side also died in the battle?
Mahabharata was a war between dharma and adharma. This is clear from what happened after the death of the Pandavas and Kauravas.
Yudhishthira was shocked to see Duryodhana in heaven while his brothers were in hell. This peculiar phenomena was explained by Indra.
Then Sakra, the lord of the deities, endued with blazing prosperity, addressed Yudhishthira and comforting him, said, "O Yudhishthira of mighty arms, come, come, O Chief of men. These illusions have ended, O puissant one. Success has been attained by thee, O mighty-armed one, and eternal regions (of felicity) have become thine. Hell, O son, should without doubt, be beheld by every king. Of both good and bad there is abundance, O chief of men. He enjoys the fruits of his good acts must afterwards endure hell. He, on the other hand, who first endures Hell, must afterwards enjoy Heaven, He whose sinful acts are many, enjoy heaven first...."
Mahabharata, Swargarohanika Parva, Section III
Duryodhana's sins were greater than his good deeds while the Pandavas had done more good deeds than bad ones. Of course neither side was perfect but on balance Pandavas were on the side of dharma while the Kauravas were on the side of adharma.
Fighting for Dharma is not the only factor governing the lives of the warriors in a war. Each of these warriors also have their own karmic history.
...As it does and as it acts, so it becomes: The doer of good becomes good, and the doer of evil becomes evil; it becomes virtuous through a virtuous act and vicious through a vicious act. Others, however, say that the self is identified with desire alone. It resolves as it desires; it does the work that it resolves; and it attains the results of the work it does.
Brhadaranyaka Upanishad, 4.4.5
Warriors fighting for dharma are earning merit. However, one cannot forget the past karmas of these warriors. So warriors who died did not have enough karmic merit to survive the war.
Mahabharat was not a war of Dharma and Adharma.
I pray to thee, O bull of the Kshatriya race, let not the Kshatriyas, old in learning and old in years, perish miserably, O Janardana, for thy sake. Oh, let this swelling host of Kshatriyas perish by means of weapons on that most sacred of all spots in the three worlds, viz.
Read this for more information.