The meaning of Dharma doesn't mean following the good path, but what it means is following your path (which you feel is right), whether it's good or bad, will be determined by God. So in a way, a competent thief is following his dharma in a better way than an incompetent policeman. The world constitutes both good and evil to balance.
We might think that the fighting on Kaurava's side was immoral. But morality is often difficult to understand. Though Krishna was on PAndava's side, majority of the warriors were on Kaurava's side. Not all were immorals. Warriors did what felt right to them during then. The relevant text can be obtained from "Dice game" event in Bhishma's own words (from this answer):
Bhishma answered, I have already said, O blessed one that the course
of morality is subtle. Even the illustrious wise in this world fail to
understand it always. What in this world a strong man calls morality
is regarded as such by others, however otherwise it may really be; but
what a weak man calls morality is scarcely regarded as such even if it
be the highest morality.
Bhishma accepted his Dharma as to serve the throne of Hastinapur, in this case it was the King Dritharshtra, hence he sided with Kauravas.