This immediately follows another statement of R. Kahana's, which also quoted an exegesis of R. Nasan b. Minyome's in the name of R. Tanchum. Quoting another statement from the same people is pretty common in the Bavli.
But there can be a deeper explanation also:
Tora T'mima (ad loc.) shows that the brothers must not have known that the pit had snakes and scorpions (see there for why). Then he notes that this is not surprising, since the term used for putting him into the pit, וישליכוהו, implies a distance of greater than twenty cubits, and one sees e.g. from the rules of Chanukah that people don't properly see that far. In fact, he notes, that rule about vision is the basis for the passage immediately before the one about the pit in Shabas. And that explains why the pit is brought in at that juncture: because the same basis underpins it as the preceding passage.
Meshech Chochma (also ad loc.) cites a midrash that says that Joseph recited the benediction "…who performed a miracle for me here" years later at the site of the pit. This, he says, is because even though his rise to power as viceroy of Egypt was also miraculous, it wasn't a supernatural miracle like being saved from snakes and scorpions, and the benediction is recited only on the latter. Likewise, we recite "… who performed miracles for our ancestors…" only for the Chanukah miracle of the oil, which was supernatural, and not for the miracle of winning the war. The rule that the menorah must be lit where people can easily see it, viz for publicizing the miracle, is related to the benediction, so the passage about Joseph and the pit comes right after that rule.