Because when the onion is cut, the stuff that is kept neatly compartmentalised inside the cell all spills out and cross reacts. This forms a compounds that goes into the air and turns into acid in your eyes. Your eyes then produces tears in order to flush it out.
Onions have evoled this mechanism to make them unpalatable when eaten. However, us humans thwarted their plans when we invented cooking and found that they actually taste pretty good.
When you cut an onion, you break cells, releasing their contents and enzymes that were kept separate now are free to mix and produce a volatile sulfur compound that wafts upward toward your eyes. This gas reacts with the water in your tears to form sulfuric acid. The sulfuric acid burns, stimulating your eyes to release more tears to wash the irritant away
When you chop an onion, the cells you’ve cut into are damaged, and a chemical reaction happens in them. This produces a chemical called syn-propanethial-S-oxide, which gets into your eyes and irritates them, making them water and hurt.
As you chop up an onion, you break open cells inside it and cause a type of volatile gas called the ‘lachrymatory factor’, or LF. When this reaches the eye, it causes a reaction in the tear glands, which attempt to flush out the irritant with tears.
This can be prevented by cutting onions underwater, to prevent the LF from reaching the eyes. Other solutions are freezing the onion beforehand, or having a fan blowing the LF away from you!