Why did Shakespeare choose for the witches to be ugly and always to be in lonely places?
I believe it was traditional for people to think of witches as old, ugly, and living in isolated places. This was because there were many old women who were unwanted by society and who had no one to protect them or support them. This is a common fate for some old women all over the world. They can't contribute anything to their society, they can't support themselves, and they are ostracized. In order to survive, they live in hovels as squatters and eat anything they can find. This is the reason that witches had a reputation for putting rats and toads and snakes in pots to boil. They were actually eating these things but were thought to be using them to cast evil spells on people. Some of them pretended they had magic powers and sold charms and powders to earn a few pennies to live on. Human cruelty extended to accusing these wretches of all sorts of evil witchcraft and burning them at the stake. It was a way of getting rid of old women who were a burden, a nuisance, and a cause of guilt feelings to those who knew they could have treated them with more charity. In some places old women who are useless are still taken out into the wilderness and left to die. In some parts of Africa they are left in the outback for the hyenas to eat. This is a quick death because a pack of hungry hyenas can polish off an old woman in about five minutes. Such women may actually become malicious out of bitter resentment.
Macbeth's witches may have been inspired by the 1526 painting, "Saul and the Witch of Endor," by Jacob Cornelisz van Oostsanen. In the Bible, Saul meets with one woman, but in van Oostsanen's painting he appears to have met a whole coven.
You might also check out this question, and especially the link about King James in answer #2.
Or this one: