The sugar was always there
A raw onion holds about 5% sugar. That is close to an apple. We do not notice it because the sharp smell covers it.
Heat removes the sharp part
Cutting an onion makes sharp sulfur compounds. Heat breaks them down in a few minutes. Longer, slower heat also browns the sugar and adds depth.
Taste a strip at 2 minutes and at 5 minutes. You will feel the change yourself.