Onions stimulate tearing because during cutting they release substances into the air, including thiopropanal oxide, which are irritating to the eye.
The tear is therefore a defense reaction, carried out to dilute the vapors released by the chopped onion.
A trick to avoiding an annoying cry is to wet the knife or onion itself before starting to cut.