Muscle spasm is not constant. It springs into action at a certain point in the range of motion to protect arthritic joints, sprained ligaments, or the injured area. In these cases, the muscle spasm is largely beneficial. For example, when part of the meniscus is displaced at the knee, the hamstring muscles contract to prevent full extension of the joint, thus sparing ligamentous over stretching. This is advantageous and the treatment should not be to relax the muscle but to reduce the displacement.
Muscle spasm results from a lesion and is abolished when it's cause ceases to operate.
It is not muscles guarding the damaged tissue which sets up the pain, it is the lesion itself. The muscle is only a protector of the lesion which causes the pain. The fibers of a ligament, tendon or muscle are like strings of a violin in that they run parallel to one another. When fibers tear, it is as though the strings are cut. Instead, in the body's enthusiasm to heal, the fibers are not only joined end to end, but they also stick to those running parallel to them, as if all the violin strings were glued together.