The witches tell Macbeth that he will be defeated only if Birnam Wood comes to Dunsinane. This should give Macbeth a very good reason to avoid Dunsinsane, so that his enemies never focus on it. If I were Macbeth, I would probably burn down Dunsinane, and then move to another part of the country. Why does he, instead, fortify it? The prophecy does not say that he will be defeated when Dunsinane is overrun; it says that he will be defeated when Birnam Wood comes to Dunsinane.
TL;DR: Shakespeare’s Macbeth is based on real events in the history of Scotland, as filtered and embellished though chronicle and tradition, and so the answer, unsatisfactory though it may be, is that Macbeth went to Dunsinane because that’s what it said in Shakespeare’s historical sources, whereas the prophecy is legendary and so not something that the historical Macbeth would have needed to take into account.
But after that Macbeth perceived his enemies’ power to increase, by such aid as came to them forth of England with his adversary Malcolm, he recoiled back into Fife, there purposing to abide in camp fortified, at the castle of Dunsinane, and to fight with his enemies, if they meant to pursue him; howbeit some of his friends advised him, that it should be best for him, either to make some agreement with Malcolm, or else to flee with all speed into the Isles, and to take his treasure with him, to the end he might wage sundry great princes of the realm to take his part, & retain strangers, in whom he might better trust than in his own subjects, which stole daily from him: but he had such confidence in his prophesies, that he believed he should never be vanquished, till Birnam wood were brought to Dunsinane; nor yet to be slain with any man, that should be or was born of any woman.
Soon he [Macbeth] encamped at Dunsany, having made up his mind to await his enemy there. For he thought it would be a disgrace to quit the throne without having fought a battle. But some of his friends urged him either to make peace with Malcolm on acceptable conditions, or to take the royal treasury and beat a retreat to the Hebrides, where he could hire mercenaries more reliable than the men who were draining away from him every day. But the Fates hurried the man onwards, for he was convinced that he was unconquerable until Birnam Wood had been brought there, so that death was not threatening him, since the soothsayers had predicted that he was not going to be killed by a man born of woman.
Dunsinane Hill near Collace in Perthshire is a strong defensive position, rising 250 metres from the surrounding plain, and it is the site of an ancient British hill fort, so it would not be surprising for Macbeth to have camped here when retreating from Malcolm’s invading army.
Shakespeare seems to have taken Holinshed’s “castle of Dunsinane” as referring to a stone castle with rooms and walls, but nothing like that has been found at Dunsinane Hill. There’s evidence of a defensive earthwork which was likely surmounted by a wooden stockade, but no traces of buildings. Hill forts like this are thought to have been generally used as refuges in times of emergency, not as fortified settlements like medieval castles.
Boece (and hence Holinshed) says that Macbeth’s and Malcolm’s armies fought an engagement near Dunsinane, but that Macbeth, being defeated, fled north to make a last stand at Lumphanan in Aberdeenshire. Shakespeare simplified this part of the story by having Macbeth come to his end in “Another part of the field” (Act V Scene VIII).
TLDR: Macbeth's interpretation of the prophecies was that he would never be defeated, so he didn't think he needed to avoid Dunsinane.
In act IV, the witches gave Macbeth three prophecies. The first is:
beware Macduff; beware the thane of Fife.
The second is:
for none of woman born shall harm Macbeth.
The third is:
Macbeth shall never vanquished be until Great Birnam Wood to high Dunsinane Hill shall come against him.
Combined, Macbeth interpreted both of these prophecies as that he could never be defeated. After the second prophecy, Macbeth says:
Then live, Macduff: what need I fear of thee?
After the third, he says:
That will never be. Who can impress the forest, bid the tree Unfix his earth-bound root?
This is listed in the website TV Tropes under the category "No Man of Woman Born", and they list a lot of similar prophecies with conditions that the recipients interpreted as "never", but which actually came true.
"Agamemnon couldn't be killed in his house or out of it, naked or clothed, feasting or fasting. He was killed in his bath house, covered with a net, while eating an apple."