The two words also differ in their underlying spatial meanings.
隣 tends to emphasize adjacency within an arrangement of comparable entities: neighbors, consecutive seats, adjacent houses, neighboring towns.
横 emphasizes the lateral side of something. It can describe not only an object positioned beside another, but also its physical side or horizontal orientation.
For example:
隣の家 — the neighboring house.
机の横 — the side of the desk.
横に並ぶ — to line up horizontally.
横に寝る — to lie sideways.
You cannot freely substitute 隣 for 横 in these latter expressions.