Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:52:29

So remind ˹O Muhammad˺, for you are not, by the favor of your Lord, a soothsayer or a madman.  

So remind, persist in reminding the idolaters and do not desist ˹from this˺ even if they say to you that you are a soothsayer or a madman. For by the grace of your Lord, by His bestowal of grace on you, you are neither soothsayer (bi-kāhinin is the predicate of mā) nor madman (wa-lā majnūnin, a supplement to it).
القرآن:٥٢:٢٩

فَذَكِّرْ فَمَا أَنْتَ بِنِعْمَتِ رَبِّكَ بِكَاهِنٍ وَلَا مَجْنُونٍ  

{فذكِّر} دم على تذكير المشركين ولا ترجع عنه لقولهم لك كاهن مجنون {فما أنت بنعمة ربك} بإنعامه عليك {بكاهن} خبر ما {ولا مجنون} معطوف عليه.

See similar narrations below:

Collected by Qurʾān
quran:68:2

You are not, ˹O Muhammad˺, by the favor of your Lord, a madman.  

You are not, O Muhammad (s), by the grace of your Lord, a madman, that is to say, madness is precluded in your case, on account of your Lord’s grace to you by way of ˹His assigning to you˺ prophethood and in other ways — this was a refutation of their saying that he was a madman.
القرآن:٦٨:٢

مَا أَنْتَ بِنِعْمَةِ رَبِّكَ بِمَجْنُونٍ  

{ما أنت} يا محمد {بنعمة ربك بمجنون} أي انتفى الجنون عنك بسبب إنعام ربك عليك بالنبوة وغيرها وهذا رد لقولهم إنه مجنون.