In pathfinder, undead are the product of sinister magic inflicted or taught by fiends, evil aberrations, or dark gods. The magic denies a soul passage to the afterlife while twisting it into a mockery of its former self. Lesser, mindless undead may be little more than constructs, but the spells used to make them have a corrupting influence on the caster's spirit. The magic that creates undead is literally meant to turn something evil, so while there may be exceptions to the rule, they are almost always struggling against the magic that animated them in the first place.
However, some settings will work under other assumptions fitting their story and world. Additionally, there is nothing to suggest a sufficiently powerful archmage couldn't modify the rules of reality in such a way as to allow undead of good or neutral alignments to exist.