Danielsson et al., (2020) in BioMed Central [BMC Musculoskeletal Disorders] reviewed 26 studies on the mechanism of hamstring injuries. They conclude that the stretch-type injury is caused when the hip is flexed (when you raise your knee towards the chest) and the knee is extended (straightening) towards the late swing phase of a kick or running action. As the knee approaches this straight position, during high speeds, the hamstring muscle group suddenly tries to slow the leg down, to prevent the knee from hyperextending. This excessive strain on weak or fatigued hamstrings, overloads the muscle group and causes it to fail.
Image from solutionssportstherapy 08.06.2021