All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
If a person who is performing ablution hears the athaan, he should say what the muaththin is saying, based on the general indication of the statement of the Prophet “If you hear the athaan, then say the same thing that the muaththn says.” [Al-Bukhaari and Muslim]
Al-Fataawa Al-Kubra of Ibn Hajar al-Haytami reads:
“And he – may Allah benefit (Muslims) with him – was asked about a person who is performing ablution and hears the athaan, should he repeat the same thing as the muaththin says or not?
He replied, ‘If he is performing ablution, then he should repeat, because a person who is performing ablution should remain silent except if he is saying Thikr (expressions of remembrance of Allah), and there is a difference of opinion about the recommendation of saying a particular Thikr upon washing each of the body parts. The most correct opinion is that they are not recommended, as stated by An-Nawawi, because the ahaadeeth that were reported in this regard were either reported by a liar or someone who was accused of lying.’”
If someone has performed ablution and he enters the masjid, it is sufficient for him to pray two Rak‘ahs (units of prayer) with the intention of praying Tahiyyat-ul-Masjid (greeting the mosque) and the Sunnah of ablution as well as the Raatibah (regular supererogatory prayer performed before or after the obligatory prayer.)
The fatwa of Shaykh Ibn ‘Uthaymeen reads:
Question: “If a person enters the mosque at the time of the athaan of the Thuhr and he prays two Rak‘ahs with the intention of performing Tahiyyat-ul-Masjid and the Sunnah of ablution and the Raatibah before the Thuhr, is this permissible?”
Answer: “If he intends with this prayer Tahiyyat-ul-Masjid and the Raatibah, then this is sufficient.
What appears to me – and Allah knows best – is that the saying of the Prophet : ‘…and then he prayed two Rak‘ahs’ does not mean two particular Rak‘ahs; rather, the intended meaning is that one prays two Rak‘ahs, even if it is an obligatory prayer. Based on this, in the example mentioned by the questioner, we say: these two Rak‘ahs are sufficient for Tahiyyat-ul-Masjid, the Raatibah prayer, and the Sunnah of ablution.”
If a person wants to pray two Rak‘ahs for each of the mentioned prayers, which is better according to some scholars, it appears that he should start with the two Rak‘ahs of Tahiyyat-ul-Masjid, then the Sunnah of ablution, and then the Raatibah prayer.
Shaykh Ash-Shirwaani said in his commentary on At-Tuhfah, quoting Shaykh Ash-Shabraamallisi [and he endorsed what he said], “If a person performs ablution and then enters the mosque, then the most correct opinion is that if he only performs two Rak‘ahs, then he may intend either of the two reasons, or both of them, and this is sufficient in principle in the Sunnah, but it is better if he prays four Rak‘ahs (two and two), and he should start with Tahiyyat-ul-Masjid; by doing so, he does not miss the Sunnah of ablution.”
Allah knows best.