Cutting an onion ruptures cells and mixes enzymes with sulfur compounds, producing the volatile lachrymatory factor syn-propanethial S-oxide (also called propanethial S-oxide). That vapor reaches your eyes, reacts with moisture to form a mild acid, and irritates corneal nerves—so your eyes water to flush it away.
Source: Live Science — Why does slicing onions make you cry?