Like any language, Japanese has multiple words for denoting location. There are two words for “next to” which might confuse students: よこ and となり so let’s take a closer look. Both of them conveniently are translated as “next to” in textbooks but there’s a little bit more to it.
よこ means that the object is horizontal in relation with another object. They both exist on a horizontal plane. An accurate translation for this word would be “adjacent to” or “side to side” in English.
となり means that the object is a neighbor, in fact, the closest neighbor out of a set of objects. It’s mainly used for things that are in the same group, like saying a table is next to a closet (furniture), or that a book is lying next to a magazine (reading material). Unlike よこ the object doesn’t have to be in a horizontal plane, but can be anywhere, as long as it’s closest.
ながさきのとなりはさいかいです。Next to/closest to (the city of) Nagasaki is Saikai.
本のよこにリンゴがあります。There’s an apple next to the book. (horizontally)
On its own となり or となりの人 is frequently used to denote your neighbor living next to you.