Bah. Magic is forbidden in Islam, but visit street markets in Jeddah or Riyadh, or even in the shadow of the Ka'bah, and you will find vendors hawking ta'wiz (talismans that are basically magic good luck charms, but because they're purportedly "holy" rather than "magic", it's considered passable.)
Same idea as Christians who would say that witches and magic are abominations, but have crosses with drops of water from Lourdes in them, or St. Christopher medallions.
Old habits die hard, and talismancy and divination are VERY old habits for the human race.
Yeah, religion and magic are extremely intertwined...prayer is based on what psychologists would call magical thinking, after all, and look no further than Catholicism or faith healing for examples of magic in American religion.
It stems from the Biblical prohibition against sorcery, which in reality was only against certain forms of magic, since Jewish religion made regular use of divination. For example, when you're reading the book of Samuel (and others) and it refers to David asking God (for example) "Should I go up to Hebron?" and God says, "Yes" and some other extended speech, the actually answer was just "yes." This answer was obtained by a method of divination which isn't entirely understood but involved drawing two cultic objects called the Urim or Thummim, with one corresponding to "Yes" and one to "no."
They also used lots. The point was, this "magic" was supposed to work because God directed it (hell, Mennonites used to use lots to select their pastors) whereas other magic, like necromancy, was forbidden - that's why Saul only resorted to it when he was at his most desperate, and all it got him was news that he'd be dead soon too. But really, what's the difference? Probably the rules were made up by the same people who decided 99% of humanity was unclean to prevent Israelites from eating dinner with foreigners.