Ok, the death penalty can occur for the following: murder, assassination, theft (only repeated petty theft, or theft of a particularly valuable or volitile thing, like important documents), betrayal of one's liege, treason to the crown, piracy, brigandtry (being a brigand or highwayman), rape, open worship of outlawed deities (usually only for repeat offenders), unlawful use of magic (cohersion by charm spells, unlawful necromancy, etc.) and arson being the most typical. It can vary from one lord's land to another, but the majority of these crimes have punishements determined by the king.
For the sentence of death, it usually goes like this. The person's typical lifespan is assessed, and their service only lasts as long as their "natural" life would, or twenty years, whichever is longer. After their service is up, the undead are destroyed and their bones burned to prevent them from being re-used by the unscrupulous. The undead are fitted with a magical collar which is linked to a person who controls a certain number of undead by the virtue of a linked magical item.