as salaamu alaykum wa rahmatullah,
As far as I know, because of the hadith that sis sofia mentioned that commends the one who preserves/teaches forty hadith, many scholars composed forty-hadith collections, to such an extent that it became almost a type of genre of book. Imam an-Nawawi sought to do that as well so that's probably why it's known as 'the forty hadith collection of Imam an-Nawawi', just as those other books were probably known as 'the forty hadith collection of Ibn alMubarak/alAsfahani/adDarqutni, etc
but he also mentions in his introduction that while others made their hadith collections centered around a particular topic or issue (adab, zuhud, jihad, etc) he wanted his collection to contain all the foundational hadith of the religion, those hadith that were called by the scholars "1/3 of religion" or "half of Islam", etc. so perhaps he found more than forty that he felt were essential to include. He also says in his introduction that the text (about the one who preserves forty hadith) is actually a weak text, but many scholars agree that it is permissible to act on a weak text when it comes to fad'ail a'maal. However he goes on to say that he is actually writing this book based on the more general teachings of the Prophet
: 'Those of you who are present should convey (this knowledge) to those who are absent', and 'May Allah illuminate the one who hears what I say, understands it and then conveys it to others in the exact manner in which it was said' so that may be another reason why he didn't stay within the exact '40 hadith' framework.