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.
Whoever enters the mosque before the Iqaamah (the call for the establishment of the prayer) and does not have enough time except to pray the two Raka's of salutation to the mosque or the supererogatory prayer before the obligatory prayer, then it is better for him to pray the supererogatory prayer, because since the salutation to the mosque is done by praying two separate Raka's then this can be achieved by praying an obligatory prayer or a supererogatory prayer. The purpose of praying two Raka's of salutation to the mosque is for prayer to be the first thing one indulges in. So if one starts by praying a supererogatory prayer, or an obligatory prayer, then that is sufficient and the purpose of saluting the mosque has been achieved. There is no difference of opinion among the four schools about this issue.
Imaam An-Nawawi said: 'It is not a condition that when one prays two Raka's to intend them for the salutation to the mosque. If one prays two Raka's intending any kind of prayer, or intends two Raka's supererogatory prayer, or any other prayer, or an obligatory prayer which is presently due, or making up for a missed obligatory prayer, then this is sufficient for him. In such a manner, what one intends by praying the two Raka's is achieved and the two Raka's of salutation to the mosque are included in that as well, and there is no difference of opinion about this. Similarly, if one intends the obligatory prayer and the two Raka's of salutation to the mosque, or intends the supererogatory prayer and the two Raka's of salutation to the mosque, then one achieves both purposes without any difference of opinion on this.'
Allaah knows best.