So [Jesus] left Judea and returned to Galilee. He had to go through Samaria on the way.
— John 4:3-4 NLT (emphasis mine)
In Jesus' day, the land of Israel was loosely divided into three distinct areas: Galilee to the north, Samaria in the centre, and Judea (where Jerusalem was situated) in the south. The Mediterranean Sea formed the western border; while the Sea of Galilee, the River Jordan, and the Dead Sea formed its eastern border.
You couldn't walk from Judea in the south to Galilee in the north, or vice versa, without travelling through Samaria. However, you may have heard it taught that ancient Jews refused to travel through Samaria, and used to cross the River Jordan twice in order to avoid doing so.
This is not true.
First, the New Testament doesn't support this theory. Jesus travels through Samaria in John 4 because he physically "had to" (v.4), and he and his disciples also do so in Luke 9:52-56 and 17:11-19. So does Philip (Acts 8:5, 26), Peter and John (Acts 8:14-15, 25), and Paul and Barnabas (Acts 15:3).
Second, the first-century Jewish historian Josephus writes:
“For rapid travel, it was essential to take that route [through Samaria] by which Jerusalem may be reached in three days from Galilee.”
— Josephus, Life of Josephus, 269
It didn't make sense to avoid the quickest route just because of tribal tensions.
Jesus
Jesus would have frequently travelled through Samaria throughout his life. This trip was therefore nothing unusual. The unusual thing in this story is that he rests at the well outside of Sychar rather than heading into the town itself (see John 4:5-6).
Men didn't visit wells.
From a cultural perspective, he's in the wrong place.
But then so is the woman he meets there.