40 number has many special meanings that lies with Allah SWT only. As per Rasulullah (pbuh) said all or most prophets are given prophethood at the age of 40. Muhammad (pbuh) was given first revelation few months less than the age of 40.
In other references from Quran and hadith, age 40 is the age of maturity. Rasulullah said in an hadith that a person's characteristic is mostly formed and completed at the age of 40, very little change can happen to one's characteristic after age 40. Allah knows best, but after studying Quran and Hadith, my learning about prophethood are -
1. it comes from Allah SWT only
2. Allah gives it to whom HE wishes to be
3. maturity and certain level of learning to acquire wisdom before prophethood is must
4. If Allah don't send revelation, no prophet can bring it from Allah SWT
5. Prophethood is majorly for - inviting people to one and only GOD (Allah SWT), bring changes in society, lead by example, etc.
to do all these, a person must acquire wisdom and then health. That is why age 40 is chosen by Allah SWT for giving prophethood. Allah knows best, and we know nothing. 40 is a very surprising number related in other areas as well, such as -
- a child's status in the womb is changed in every 40 days
- as per hadith to change one's habbit require repeating the action for 40 consecutive days or 6 weeks (science has just proved it after 1400+ years!!!)
- Musa/Moses (pbuh) was called for 40 days and nights to get TEN commandments
- When Musa/Moses (pbuh) requested to see Allah SWT, but couldn't see and become senseless before the reflection. He was sensless for 40 days
- Noah (pbuh) and his companions were floating in the ship (made by Allah's instruction) for 40 days
- Allah specially ordained all human being to take care of their parents at the age of 40 (when parents age reach at 40). Allah SWT said in the Quran to behave softly with them when they reach the age of 40
- etc. etc. many more
To answer your question in a line - "40 is the age of certain maturity or wisdom for prophethood, defined by Allah SWT, and HE knows best about the answer". As Allah said in the Quran that everything happens at its' precise and predestined timeline, not before the moment or after the moment.
Anything i have said wrong, i am mistaken myself and may Allah forgive me for that, amin. Allah is completely error-free, and we are full of errors, may Allah forgive us for that, amin.
May Allah bless you, amin.