Where does the energy of formation of covalent bonds come from?
Your view of bonding is a little simplified and confused. For the details it is worth reading the great answer referred to in some comments already: Fundamental forces behind covalent bonding .

I'll stick with a simpler view that focusses just on the energy involved and not the mechanism of chemical bonding. Firstly, you are wrong that boding two hydrogen atoms needs an input of energy. It actually releases energy. This is a thermodynamic view of the reaction. This tells us whether there is more or less energy in the product of the reaction being described than in the chemicals being combined to create the product.

But a lot of chemical reactions are thermodynamically favourable (that is the reaction releases energy) don't happen easily (this is probably not true for atomic hydrogen which should react very easily to form H2). But there are plenty of other reactions that release energy according to thermodynamics but that don't happen easily. For example, elemental carbon plus oxygen will release energy if converted to CO2. But neither the diamond in jewellery or the coal in your fireplace (which is basically impure carbon) reacts easily to give carbon dioxide despite being in an environment with a lot of Oxygen gas in it. Here the problem is that room temperature oxygen molecules and carbon just don't have enough energy to kick off the process that creates the product. This is where we have to look at the kinetic view of the reaction rather than just the thermodynamics. Although the overall reaction is favourable according to thermodynamics, we need to add energy (firelighters for coal fires, a blowtorch or diamond rings) to the mixture to give the atoms in the reactants enough energy to overcome the kinetic barriers to the reaction. Think of having to climb a tall mountain to get to a lower valley on the other side. Or think of giving oxygen molecules enough energy to break carbon atoms apart from their normal solid structure.

Once coal or diamond are warm enough, the reaction will happen spontaneously and you have either destroyed your engagement ring or you have a nice coal fire. In this case you can feel the energy released from the reaction as a pleasant warming of your room. 

Back to the question. The energy involved in a reaction is an accounting of the amount of energy used in the bonding of the products versus the reactants. The energy released in reactions such as burning carbon goes into the environment as heat. Other reactions happen spontaneously (try dropping a small lump of sodium into water). Some reactions require a tiny amount of encouragement (oxygen and hydrogen in certain concentrations will react explosively to form water when encouraged with the tiniest spark). 

We can drive some reactions the other way using inputs of energy. For example we can electrolyse water into a mixture of hydrogen and oxygen. This requires us to add energy to the system (about 286kJ/mol) because the products are in a higher energy state then the reactants.

If you just focus on the thermodynamics of a reaction the numbers (kcal or kJ/mol) tell you how much the energy difference between the products and reactants is. But many reactions that should release energy require some input to kick off the reaction. This is confusing, but chemistry wouldn't be interesting and we wouldn't exist if thermodynamics were the only thing driving reactions. 

Also energy is not created or destroyed here, just moved around. You can put energy in to a system to drive a reaction or the environment gets energy back from reactions that release it.

So, some reactions require energy to drive them because the products have higher energy, some release energy because the products have lower energy but many release energy but, confusingly,  require some energy input to kick off the actual reaction process.