Abarbanel asks this exact question ("אין ספק שבא הפסוק הזה שלא במקומו"), and appears to answer that the reason is because a practitioner of these magics does not belong among the nation of Hashem ("ואין ראוי שישב בתוך עם ה"). It's possible to understand this as saying that the reason the verse is outside the rest of the chapter is to emphasize the degree that such a person should be banished from among the people.
But he does not say this explicitly.
Seforno says that the reason is to emphasize the capital punishment given to such a person.
ומאחר שהיתה הכונה בכל אלה לקדש את ישראל הנה מי שיסור מזה באוב או ידעוני אשר ענינם כולו ברוח טומאה על היפך כל המכוון ראוי שיסקל בלי ספק
However, I don't understand why this sin is singled out, as the beginning of the chapter talks about people who sacrifice their children to Molech, which seems to be much worse.
As noted in several places (ex. here), the fact that verse 27 is at the end forms a chiasm \ inclusio \ envelope around much of this chapter (between v.2-27 or v.6-27).
Daat Mikra writes (my translation; paraphrased)
The end of the chapter parallels the beginning (v. 6). The reason is to emphasize against these sins. The paragraph ends with one detail after it concluded the general rules, similar to Deut 14:21.
The purpose of this structure, and the special significance of Ov and Yidoni, is explained by R' Leibtag:
From a thematic angle, based on Sefer Devarim, OV & YID'ONI takes on additional significance. See Devarim 18:9-15 where the Torah forbids us to approach any type of 'future teller' or 'soothsayer' including the OV & YID'ONI. Note how similar those psukim are to Vayikra chapter 18!! There, the Torah explains how we must follow the guidance of a NAVI, and not look for guidance from those who use 'other methods'.
Every nation has its spiritual leaders. To become an AM KADOSH, we must be sure not to follow after these people who offer 'shortcuts' to spirituality by 'bringing up the dead' or 'reading palms' etc. As God's nation, we must recognize that our fate is solely in the hands of God, and thus a direct function of our deeds. Belief that certain events are pre-determined or believing that by bringing up the dead we can get an 'inside word' on what will happen, etc. negates the very basics of Judaism and our belief in 'hashgachat Hashem' as a function of our deeds. [see daily kriyat shma etc. / 've-akamal']
Academic scholarship (cf. Anchor Bible et al.) offers the following opinions:
Scribal error. This verse was meant to be included earlier in the chapter, but it was accidentally skipped and got inserted at the end instead.
Added later. This law was written later than the others, and was thus appended at a later date.
However, there is no evidence for either of these answers, and the second is particularly problematic.
Another opinion I saw is that this verse is a transition to the next chapter, which talks about Kohanim and dead bodies. (I don't see how, though. I get the dead connection, but don't see the leap to Kohanim.)