While under “enemy” rule (be it Egypt, Assyria, Babylon, or Persia) the same events would come to pass on repeat. Assimilation into each nation's rule would take place as the Israelites were pretty much a perpetually conquered people. In this, SOMETIMES idols, gods, and other forms of worship would make their way into the Hebrew life. It was actually pretty normal and it went something like this:
“Oh, you want us to acknowledge _____? Fine, whatever... I've go things to do.”
And the Israelite went about their business because after a while they were used to it. With it came greetings and salutations (apparently) as noted by a letter written written from Jerusalem to the Jewish colony in Egypt called Elephantine, the Jewish priests wrote blessings to the Assyrian god as that was their ruler and... by law they probably had to do that.
Realize that none of the time they were captured provinces (at the time of the bible's writing) were they made to abolish their native form of worship. On the contrary it was customary at the time during peaceful conquests for the conquering nation to pay some acknowledgment to the god of their new captive area. Jewish people still worshiped their god YHWH, but they also believed OTHER gods and spirits existed. So they had a belief in many gods and spirits... but only worshiped one god (YHWH). They also believed that angels had certain domain over certain natural things (like land and air) and they could inhabit things like statues and people. This concept would be a problem later when (maybe) Paul wrote in Colossian 2:18 not to worship angels.
So there was an influence of worship from other nations and their gods and spirits... and there was a possibility of individual Jews to take concepts of angels too far. If you had a different version of the bible, it would imply more of a spirit IN her or her being “familiar” with the spirit. This is more along the lines of the concept being discussed and this is where stoning would occur. It's not necessarily a spirit medium – it's just “spirit medium” is the easiest way to translate that.
It's basically saying if you fraternize with other spirits and one gets into you... you die. And fraternizing with other spirits was not only pretty easy, belief in the dangers of other gods was a very real fear.
Although there is no real evidence that the Israelites followed this law to it's strictest sense at the time... LOL.