The opposite charges are going to attract and the like charges are going to repel. We’re talking about interactions BETWEEN the two atoms here, so we’re putting aside the Nucleus A/Electron A and Nucleus B/Electron B interactions. for a moment. With the Coulomb equation in mind, there’s at least 4 things we need to think about:
1) the attraction between electron A and nucleus B
2) the attraction between electron B and nucleus A
3) the repulsion between electrons A and B
4) the repulsion between nuclei A and B.
If you think about it, the first two interactions are actually the same magnitude. So there are two attractive forces between the electrons in these positions between the nuclei. Opposing this attractive force is the repulsion between the two electrons. Overall, the attractive force between the electrons and the nuclei dominates the electron repulsion term, leading to the observation that the interaction energy increases as the intermolecular distance decreases.
So in a nutshell, the attractive force is inversely proportional to the distance. The closer they are, the stronger the attraction. The electrons are at the frontier of the atom and therefore they are closer to the other nucleus. Since the distance (x+y) is going to be shorter in the Coulomb equation than the internuclear distance (x+y+z), attraction will dominate at longer distances.
However, there’s a catch. When d gets small enough (i.e. when “y” in our equation becomes small), the repulsion between the nuclei starts to come into play. See the inflection point in the graph below? As the atoms get closer together, the rate of change in interaction energy with distance begins to decrease, and eventually reaches a minimum. Eventually they meet a “sweet spot” where the two forces are in balance.
The name we give this “sweet spot” is the bond length.
And the stabilization energy at this distance? It’s called the bond dissociation energy (or sometimes the bond strength).
Another way to think of it is the Goldilocks point. Not too long, not too short – just right, so that the attractive and repulsive forces are balanced.
I made a rough little diagram of the interaction which is depicted here:
A more official looking graph of this interaction comes from LiqC of (now-defunct) Carbon-Based Curiosities, who gave me permission to reproduce his beautiful looking graph of this interaction energy.
Note the Goldilocks spot at a bond length of 74 picometers (0.74 Å) and energy of 432 kJ/mol, and how ΔE skyrockets as you decrease the bond length past this point.
There are metaphors for these type of interactions all over the place. Your parents might drive you nuts [far left hand area of graph]. So you decide to go to school somewhere far, far away [far right hand part of graph]. Then you find that, surprise surprise, you miss them. So you move back to the area. But not too close!
Note – this discussion doesn’t invoke orbitals or quantum mechanics, but in order for the electrons to exist in close proximity in our example, they must have opposite spin. This is due to the Pauli exclusion principle, which states that no two electrons may occupy the same quantum state in an atom or molecule.