The starter motor failes to turn the engine some times.
When you tap the starter motor with a hammer, it starts to work.
can this be repaired without buying a newone
If you forgive the pun it smacks of a poor connection.
Striking with the hammer makes the connection good again.
Vibration of the engine sometimes makes it bad again.
This is only my guess...
Perhaps next time it happens you could wriggle wires in an attempt to find where the bad connection is. A failure in the motor itself is more than likely to be permanent and not correctable by bashing. Another guess...