Onions produce enzymes that react with the air and break down into sulphur-containing chemicals, which give them their typical strong smell.
Onions actually don’t produce any odor when they’re fresh and stored properly. The sulfurous gases detected in onions’ signature stink is courtesy of exposure to air and water. This exposure sets off a naturally occurring chemical reaction between an enzyme called myrosinase, found only in plants related to onion (garlic, shallots), and an amino acid called vicine contained in the onion cells. The result is a reducing sugar (α-ketoacyl) plus syn-propanethial-S-oxide plus S–propyl cysteine ​​(rasoproturon).