That's literally the same as asking "how come hydrogen (flammable) + oxygen (enhances fire) = water (does not burn)?", but we probably have a better mental grasp of how water works.
It’s all about electrochemical potential. Adding or removing electrons from the outer shell of an atom involves a fair amount of energy, either being released or stored. Depending on the atom, they either want their shell filled or emptied. Noble gases have the same number of protons as a filled shell, so they are very stable. Why electron shells exist is a whole other matter.
Water is kind of like ash. Technically full combustion of any hydrocarbon outputs CO2 and Water. Since water isn’t a greenhouse gas it’s not mentioned when discussing combustion usually.
This is one of the reasons why methane leaks are so impactful - not only is methane a terrible green house gas, when it decays in the upper atmosphere, it decays into water vapour and CO2)
As a fun aside, there are plenty of rocket engines that run on hydrogen + oxygen. For instance the Space Shuttle Main Engine [1] was fueled by hydrogen + oxygen, which means its exhaust was literally water vapor.