It’s because onions produce a chemical when they’re cut called ‘syn-propanethial-S-oxide’ (try saying that ten times fast!). This acts as an irritant to the tear glands in our eyes, which causes them to produces tears to try and remove the substance!
Pete’s right, when you cut an onion, it releases a gas called Propanethiol S-oxide. When this is mixed with certain enzymes in the onion, it creates a sulfur gas. These gases then get to your eyes and create a mild acid which irritates the eyes. Whilst normally, your body would tell you to close your eyes, it isnt a good idea if you are cutting an onion so to protect your eyes as best you can, your eyes make tears.