theres actually a lore blurb about this in one monster manual.
basically theres a type of Undead thats not "Evil", specifically temple guardians.
These are dudes that passed into the afterlife of their god, btu when a temple of their god is desecreted they come back and haunt their own bones to defend the temple.
Idk mang, sounds pretty noble to me