This is down to a unique chemical reaction. It starts underground, as a growing onion will absorb sulphur from the earth, causing molecules known as sulphoxides to form. When you cut into an onion, you’re breaking into its cells, which release certain enzymes. These enzymes react with the sulphoxides, converting them into sulphonic acids.
This combination results in the release of a vapour that will irritate your eyes. To flush out the irritation, nerve endings in your cornea will inform your brain of the aggravation, which will instruct the lachrymal glands above your eyelids that can regulate the release of tears, to flush it out by making you cry.