Muscles need energy to contract. During exercise:
If insufficient oxygen is available to the muscles the heart and lungs are unable to supply sufficient oxygen. This happens when exercise is vigorous and/or prolonged.
As a result, muscle cells cannot support the electron transport chain. They begin to respire anaerobically. Instead of carbon dioxide, water and ATP being produced, pyruvate is converted to lactate. Muscles continue to contract, but less efficiently.