After death muscles use up all remains oxygen till oxygen depletion leading to anaerobic conditions begins to stiffen as ATP is used up, then after a while lactic acid causes pH to drop and inhibits production of enzymes needed for respiration and then ATP is no longer produces then they become fixed in a state of contraction due to myosin and actin need this to relax. But then as the body starts to decompose muscles relax. The extent of rigor mortis can be used to determine time of death.