Imam Abu Hanifah said in ‘Fiqh al-Akbar’ p.48:
The Prophets (upon them be peace) are free from minor and major sins
Abul Muntaha adds to this in his commentary:
Meaning before Prophethood and after it
Mulla Ali al-Qari in his ‘Sharh Fiqh al-Akbar’ p.69 comments:
This protection/immunity is established for the Prophets before Prophethood and after it according to the more correct opinion
Going on to add importantly that p.73:
In it is a proof that His Prophethood was not limited to that which is after 40 (years of age) as a group have said. Rather there is an indication that from the day of His birth He is attributed with the quality of Prophethood. Rather the hadith: ‘I was a Prophet when Adam was between a soul and body’ is a proof that He was attributed with the quality of Prophethood in the world of souls before the creation of bodies.
Imam Ibn Abidin said in his ‘Rasail’ p.307:
They are protected/immune from minor and major (sins) before Prophethood and after it, whether deliberately or forgetfully