To answer you need to give more details. Does the starter motor keep on driving or is the engine dragging it?
You can determine if it is an electric problem by pulling the terminal off the starter as soon as it starts. If it does not disengage, you know it is the shaft either dry, rusty or bent. If on the other hand cutting electricity supply makes it good, you need to clean the terminals in the solenoid or replace it.
Some starters will develop a crack in the body when the engine drags the starter. If this happened, the bushes are misaligned and the starter is cactus.