Reference: http://www.alfawzan.af.org.sa/node/16882
Question: [What is the ruling regarding] extending the greeting [of as-salaam ‘alaykum] upon entering the masjid – whether someone is in there or not?
Response: [To extend] the greeting [of as-salaam ‘alaykum] is a good word, so if there is anyone inside [the masjid], then he can extend the greeting to his brothers. And if there is no-one there, then his greeting will extend to the angels who are present inside the masjid.