All praise is due to Allah, and may peace and blessings be upon the Messenger of Allah.
The hadith stating:
“Whoever learns something of magic, whether little or much, his final covenant with Allah will be broken”
is weak and cannot be used as evidence. It was narrated in a disconnected form (mursal) from Safwan ibn Sulaym. Furthermore, its chain of transmission contains Ibrahim ibn Abi Yahya, who is classified as abandoned in hadith narration.
Therefore, the additional wording:
“His prescribed punishment is execution unless he repents”
is not established through this hadith.
Repentance from practicing magic is accepted by Allah Almighty if a person sincerely repents. The door of repentance is open for all sins, even shirk (associating partners with Allah).
Allah Almighty says:
“Say, ‘O My servants who have transgressed against themselves, do not despair of the mercy of Allah. Indeed, Allah forgives all sins.’” [Az-Zumar: 53]
The magicians of Pharaoh also repented and believed in Allah after witnessing the miracle of Prophet Moses (peace be upon him).
As for whether a sorcerer's repentance is accepted under worldly legal rulings, and whether the prescribed punishment is waived if the person publicly announces repentance, scholars have differed on this matter. Some maintain that his repentance should be accepted, while others hold that it should not be accepted outwardly, out of concern that he may only be pretending to repent while continuing to practice magic.
Conclusion: The aforementioned hadith is weak and cannot be used as evidence. As for repentance between a servant and his Lord, it is accepted when it is sincere. However, its legal status in worldly matters and its effect on the prescribed punishment are subjects of scholarly disagreement.
And Allah knows best.