Suppose Necromancer A controls N undead. Her rival, Necromancer B, wishes to command those undead and turn them against Necromancer A.
What are the mechanics for doing this in Pathfinder?
Yes. When two spellcasters both should have control of a creature, they make opposed Charisma checks, per the Multiple Mental Control Effects section of Combining Magic Effects:
If the controlled creature receives conflicting orders simultaneously, the competing controllers must make opposed Charisma checks to determine which one the creature obeys.
This applies equally-well to the command undead spell as it does to regular compulsions.
Furthermore, the Command Undead feat can allow a cleric to give orders to an undead creature that another has already given orders. However, this doesn’t necessarily wrest control of the undead away from the first necromancer:
If an undead creature is under the control of another creature, you must make an opposed Charisma check whenever your orders conflict.
Obviously, you could make your order “stop listening to A,” and then A would need to win a subsequent Charisma check to override that, but it’s possible for an undead creature to attempt to follow the commands of two different necromancers at the same time.