If I understand correctly, you're asking how an existing stable bond can be replaced by another. You give the example of a stable O-H bond and a N atom, but I could give an easier example: stable H2 gas and stable O2 gas. It requires some energy to combine these, that's true. You seem to be asking why, if it requires energy, does it happen at all. Well, sometimes, there is some energy around, say an electric spark for the reaction of H2 and O2, in my example. Can you see how this is true. Does this answer your question?