The starter on my Yamaha TTR 230 wouldn't work so I took it apart and found the smallest piece of metal had flaked off and would not allow the starter to spin. I put the starter back together and it worked fine after that.
So it could be that you have/had the same problem and when you smacked it it dislodged whatever was obstructing it, albeit maybe just temporarily and your problem will return.