All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
The first time the greeting with 'As-Salaam' was legislated was after Prophet Aadam was created. Abu Hurayrah narrated that the Prophet said: "Allaah created Aadam and his length was sixty cubits then Allaah said to Aadam "Go and greet those angels with 'As-Salaam' and listen how they would greet you, and that will be your greeting and the greeting of your progeny". Aadam greeted the angels saying: "As-Salaamu 'Alaykum", then the angels replied to him: "Wa 'alaykum assalaam wa rahmatullaah"; "so the angels added to the greeting 'wa rahmatullaah'; every person who will enter paradise, will be in the image of Aadam but his progeny decreased in height until they reached the height that we have today." [Al-Bukhari and Muslim] Imaam An-Nawawi said: 'This is the first time the greeting with 'As-Salaam' was legislated.'
As regards the greeting after the Prophet was sent as a Messenger, was when Abu Thar became a Muslim. Abu Thar said: "I was the first one to greet the Prophet with the Islamic greetings as I said to him "As-Salaamu 'Alayka, O Prophet of Allaah! Thereupon the Prophet replied: "Wa 'alayka assalaam wa rahmatullaah." [Muslim] It might be understood that this was the first greeting with the wording of 'As-Salaam' after the revelation came down to the Prophet .
Allaah knows best.