Rigor mortis occurs because, after death, the muscles of the body partially contract, but they are unable to return to their relaxed state. About.com further explains that this causes the muscles to become fixed in place for around 72 hours.
Muscle contraction occurs when the muscle fibers actin and myosin are cross-bridged (moved over each other) with the help of calcium ions. After death, the muscle cell membranes become more permeable to calcium ion, causing continued contraction. In normal living muscle, ATP (adenosine triphosphate) is used to relax the muscles. However, ATP generation requires cell respiration. Existing stores of ATP do not last long after death, causing a semi-permanent contraction called rigor mortis.