There are 2 theories, phase and loudness.
It may be just that the loudness in the left ear is greater than the ear is greater than the right, indicating that the sound is to the left. The tone of a familiar sound will suggest that it is in front or behind The brain also uses reason to figure out where it will be.
This explains why it is difficult to locate low frequency sound sources, since low frequency sound waves easily travel around corners and the sound will be the same volume at each ear.
The other theory is phase. When the sounds at each ear are in phase, the sound is likely to be directly ahead, behind, above or below. when the phase one ear is marginally ahead, it pmeans that that ear is nearer to the sound. ("likely to be" because if the wavelength is too short, it wouldn't work - it could be out of phase by more than one wavelength)
This has a difficulty because neurons can only fire 2000 times a second maximum, and the phase difference can be less than 1/1600th of a second which is not fast enough. There are a couple of theories about how this may be possible, both similar, by Jeffress, and an importand computer scientist calle Licklider, which suggest two parallell delay lines of synapses, one having longer lengths of axon which slow down the signal from one ear, a bit like a wonky ladder. Only the pair of neurons that are in phase will generate an action potential. So identifying the rung of the ladder that has matched neurons at either end would identify the phase difference.
I personally think the first theory about loudness is adequate to explain sound localisation.
Currently I can vaguely hear a neighbour sanding rust from his car. My first impression is that I alread know the direction the sound is coming from, and my second thought is that this observation is consistant with what I can hear in both ears. He is outdoors. I am indoors near a window. If I was blindfolded and didn't know where I was or where he was, I would have difficulty in identifying the direction the sound was coming from.