Magic is nothing more than science not yet understood; that’s something the Doctor knows, and he uses it to his advantage. Primitive people are easy to impress with trickery; calling it magic sets them in awe of him.
Not that it always works, especially in places where ‘magic’ and ‘witchcraft’ are considered one and the same. Then things can get a bit sticky, especially as witches are, more often than not, put to death. He’s had more than his share of close shaves. But whenever ‘magic’ gets him into trouble, he can always rely on science to get him out.