Can anyone tell me the context of the following hadith, when he (sallallahu alaihi wa sallam) said it? "Trim your moustaches and save the beard"
The context of the hadith
From an overall perspective one could speak of one hadith, but in fact there are many ahadith quoting the same with different wordings and addition see for example this search result on sunnah.com.
Among the results you may find ahadith that clarify the context:
Ibn ‘Umar reported God’s messenger as saying, "Do the opposite of what the polytheists do ; let the beard grow long and clip the moustache.” A version has, “Cut the moustache down and leave the beard.” (Mishkat al-Masabih, Sahih Muslim and Sahih al-Bukhari)
The Messenger of Allah (ﷺ) said: Trim closely the moustache, and grow beard, and thus act against the fire-worshippers. (Sahih Muslim)
So the reason for this is to not do like the disbelievers. More exactly as ibn Hajar added in his commentary on Sahih al-Bukhari (on this version of the hadith) is that ibn 'Umar -as stated in the version of imam Muslim- was referring to the Majus (Zoroastrians) as stated in Fath al-Bary -see here-:
In the following I'm translating from Arabic language as the translation is of my own take it carefully!
( خالفوا المشركين ) في حديث أبي هريرة عند مسلم خالفوا المجوس وهو المراد في حديث ابن عمر فإنهم كانوا يقصون لحاهم ومنهم من كان يحلقها .
(Do the opposite of what the pagans do) In the hadith of Abu Huraira according to Muslim, do the opposite of what the Magi do, which is what is meant in the hadith of Ibn Omar, because they used to trim their beards, and some of them shaved them.
Some different opinions on the topic
However among the scholars of the shafi'i madhhab some say that leaving the beard grow is not an order but a recommendation. While there's agreement on the trimming (not shaving) of the moustache! These scholars say so because the hadith:
would basically fall in the same category, but it is not regarded as fard to change dye the gray hair by the majority of scholars. So the condition or reason why leaving the beard grow and dyeing the hair should be the same.
Many modern scholars among them Sheikh abu Zohrah, Sheikh Muhammad Shaltoot and the Egyptian house of Fatwa hold the position that leaving the beard grow is neither fard nor recommended, but among the sunan of customs like eating, drinking and clothing etc. (See wikipedia in Arabic)