This is a very dangerous habit that many horses get into. But it can be fixed pretty quickly by making them like moving away LESS than they like standing to be mounted. Kind of like "if you want to move, then I will give you a reason to, but you won't like it!"
I put just the ball of my foot on the stirrup tread so I can drop my foot back out quickly, then I bounce a bit like I am going to mount. If they step away or walk off I immediately drop my foot back out of the stirrup, pull their head around, get big, growl, swat their butt and run them in a few very quick, tight circles. Then I stop them, rub them, tell them to "stand" and do it again.
Of course this works best for mounting from the ground. Those who use a mounting block will have to modify the "step down and correct" action to take into account standing on the block.
Most horses will only take a few repeats of this and they will hold their ground like they are glued down. Some are more set in their ways and will need reminding on occasion for a while, but it has worked on all of the confirmed "move while mounting" problem horses I've ever used it on.
Good luck and let us know how it goes.