The text does not tell when Samson went to Gaza. Notably, though, the Septuagint (the Greek translation of the Old Testament) contains an extra word that does not appear in the Hebrew text, the word ἐκεῖθεν, which can be translated from there.
Thus it reads, Now Samson went from there to Gaza.
As this verse follows closely after Judges 15:19, where Samson is at Lehi, this addition in the Septuagint points to a direct chronological connection between the two events.
But we are always obligated to give priority as much as possible to the Hebrew text. And in Judges 16:1 the Hebrew gives a different impression than that of the Septuagint. For one, the term from there
is absent. Even more noteworthy, though, is the fact that Judges 15:20 functions as a kind of closure to Judges 14:1 – 15:20. The Hebrew text actually includes a major paragraph break between the end of Judges 15:1–20 and the start of Judges 16:1–31. Such paragraph breaks, we need to know, are far less frequent in the Hebrew text of the Bible than in English writing. In this case the implication is clear, that Judges 15:1 – 16:31 are two distinct units. Thus, Judges 15:20 appears to indicate that the events of Judges 14:1 – 15:20, culminating at Lehi, happened near the start of his judgeship, while the events of chapter 16 happened at the end of his judgeship.1 The implication may well be that by now, "the relationship between Israel and the Philistines may have cooled sufficiently for him to go to Gaza, with appropriate caution, and if he had reason to do so, just as he had been able to go to Timnah at the beginning of chapter 14.”2
1 Samson went to Gaza, and there he saw a prostitute, and he went in to her.