The starter is a strong electric motor with a spring loaded gear at the end of the shaft that comes out of the motor. A starter that cranks a long time, as in a motor that won’t start, can get very hot. The heat melts some of the materials that make up the armature of the motor, or the wire windings. If there is enough heat and damage the armature can short out and the motor is dead.
Many times a part of the armature goes bad due to heat and you have a “dead spot” in the motor. When the motor stops turning and it lands in the dead spot, it won’t work - no nothing. This can respond to the “whack” test of hitting the motor with a hammer and the vibration can move things enough to get the current going and the motor seems to work fine. You could get several normal starts before hitting the dead spot again.
The other way a starter fails is when the spring loaded gear gets so worn in won’t engage the starter to the flywheel. This is noisey, the starter is spinning but the car’s motor isn’t getting spun and therefore won’t start. Sometimes you hear a hum as the starter motor spins. Other times it is a loud grinding sound as the starter gear grinds against the flywheel but the teeth don’t mesh together.
It sounds like your starter falls into the dead spot category of failure.