There is still some debate over what exactly causes them, however it is believed to be due to a buildup of lactic acid caused by a muscle spasm. This can be due to injury, overuse or lack of use. The individual muscle fibers that cause the knot have continued to contract long after the muscle was being used. This chronic contraction cuts off blood flow to the area causing what feels like a tied up bit of muscle fibers.
Massage can help to alleviate these constrictions by loosening the muscle and stopping the spasm. The muscle fibers than relax and blood flow is allowed back in the area, removing waste and allowing the fibers to remain in a relaxed state.
A certain amount of knots are inevitable due to everyday life. Drinking enough water and being aware of your posture and how you are using your body can help to prevent knots from occurring.