Oh man, this takes me back. I read something in an old car magazine about this exact thing. The idea is that the starter motor itself can get a dead spot, so a good tap with a hammer can jolt the brushes or the armature free for one more turn. Yeah, it's definitely the starter body you whack, not the little solenoid on top. It's a classic last-ditch trick to get home, but it just buys you time before a real fix.
When you said it's the starter body you whack, not the solenoid, that clicked for me. I always thought a tap anywhere near the starter might help, but I was aiming at the solenoid. Like that time my old truck wouldn't start, I kept hitting the solenoid and it did nothing. Then a mechanic friend told me to hit the main motor body, and it cranked right up. Now I know exactly where to tap, thanks to tips like yours.