With "そば", you picture thing A that's nearby thing B. It is omni-directional in the sense that it doesn't matter which way those two things are facing. They just need to be close enough.
With "よこ", first picture a "そば" relationship but with an additional constraint that two things are side ways --- this word is no longer omni-directional. So for this to work, thing A has to have something that resembles a front (such as a building), and relative to this front of thing A, this B is at the 90 degree direction. Or thing B going tangental to thing A (like one street crossing another.)
With "となり", first picture a "よこ" relationship with an additional constraint that two things are next to each other.
I hope that puts those three words in context.