How is the bond length calculated from the total electronic energy?
The geometry of a system is what is known (or given) and a corresponding energy is computed.  If you have an energy then you should have the geometry (or in your case, bond length).

The wave function, $\Psi$, in the Schrodiner equation is simply a function of all the positions of the particles within the system (nuclei and electrons).  Typically chemists invoke the Born-Oppenheimer approximation which assumes that the nuclei are stationary (frozen in space) with respect to the very 'fast-moving' electrons.  Therefore, we freeze the nuclei in space and compute the energy of this stationary state.  Move the nuclei in your molecule a little bit and you will get a new energy.  

As Wildcat was explaining, optimization procedures essentially moves the nuclei in your molecule around in space, computing an energy for each configuration. The goal of this type of routine is to find an energy that is lower than all the rest.  Take, for example, the $\ce{H2}$ molecule.  It contains one bond length and therefore the only coordinate we need to consider in an 'optimization procedure' is the internuclear separation of the two $\ce{H}$ atoms.  It is the chemist which will choose the initial positions of these atoms.  Say we initially set these atoms to be 200 pm apart.  We compute an energy.  Now, can we do better?  (i.e. can we perturb this geometry in such a way that gives rise to a lower energy?)  Well we can certainly try other bond lengths so we now set our bond length to 150 pm and compute a new energy.  Lo and behold we see that this new energy is lower than the first!  We keep trying different bond lengths until we reach a point where the energy increases no matter what we do with the separation (whether we increase it or decrease it).  Once we are at this point, we have found the lowest energy configuration of $\ce{H2}$.  Of course optimization routines are smarter than doing a brute-force approach to sampling all the possible quantities each geometrical parameter can take on.  Furthermore, second-derivatives are essential for characterizing the nature of the stationary state that was determined (i.e. is the stationary state a true minimum, a transition state or some higher order saddle point?).