We here investigate the mechanism of SARS-CoV-2 3CL protease inhibition by one of the most promising families of inhibitors, those containing an aldehyde group as warhead. These compounds are covalent inhibitors that inactivate the protease forming a stable hemithioacetal complex. Inhibitor 11a is a potent inhibitor that has been already tested in vitro and in animals. Using a combination of classical and QM/MM simulations we determined the binding mode of the inhibitor into the active site and the preferred rotameric state of the catalytic histidine. In the noncovalent complex the aldehyde group is accommodated into the oxyanion hole formed by the NH main chain groups of residues 143 to 145. In this pose, P1-P3 groups of the inhibitor mimic the interactions established by the natural peptide substrate. The reaction is initiated with the formation of the catalytic dyad ion pair after a proton transfer from Cys145 to His41. From this activated state, covalent inhibition proceeds with the nucleophilic attack of the deprotonated Sg atom of Cys145 to the aldehyde carbon atom and a water mediated proton transfer from the Ne atom of His41 to the aldehyde oxygen atom. Our proposed reaction transition state structure is validated by comparison with x-ray data of recently reported inhibitors, while the activation free energy obtained from our simulations agrees with the experimentally derived value, supporting the validity of our findings. Our study stresses the interplay between the conformational dynamics of the inhibitor and the protein with the inhibition mechanism and the importance of including conformational diversity for accurate predictions about the inhibition of the main protease of SARS-CoV-2. The conclusions derived from our work can also be used to rationalize the behavior of other recently proposed inhibitor compounds, including aldehydes and ketones with high inhibitory potency.