I just learned about the Hebbian Learning Rule. It essentially says "Neurons that fire together, wire together". I'm wondering if the learning rule is affected by the spatial distance of the two neurons. When two neurons are far from each other, why is the connection formed?
It's a local rule. All that it means is that the connection between two neurons gets stronger if you use that specific connection more. The specific connection (the synapse) must be used though; it doesn't apply to two random neurons that aren't connected that happen to fire at the same time.
Hebbian learning is generic term for outcome; there are actually two separate mechanisms I know about (probably many more, too). First, there's "silent synapses" which have only NMDA receptors, but not AMPA receptors. NMDA receptors have Mg+ molecules blocking their channels and require AMPA activation to expel the NMDA. So if you have a synapse with no AMPA, it won't be an effective synapse. However, if you have another synapse activing the tissue, expelling the magnesium, then the silent synapse has a short window to activate the synapse during the Mg expulsion. As it does this, it activates a series of protein signaling and transcription signaling that tells the cell to bring more AMPA up (a response to all the Ca signaling that these signals rely on). This is also a mechanism for conditioning (the two different synapses representing the pathway of the conditioned and the unconditioned response. The conditioned response would be the pathway with the silent synapse).
Another example is astrocytic regulation of glutamate levels. ATP is what your whole body uses for energy, but there are ATP detectors in astroctyes, which couple in the tripartite synapse as a synaptic regulator. As the synapse is more active, ATP is released, which activates the astrocyte and causes it to release extra glutamate, bringing the postsynaptic neuron closer to firing.
All of these require only that the neurons make contact at a synapse, distance between somas is not a factor. Of course, the distance between the axon and the dendritic spine have to be close enough to form a synapse.