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, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
The two rak‘ahs of tawaf were legislated in connection with the ritual (i.e. tawaf). Some scholars held them obligatory in case of performing an obligatory tawaf. The preponderant opinion is that they are a confirmed Sunnah, even if the tawaf is obligatory.
This is the view of Ahmad, Maalik and Ash-Shaafi‘i in his preponderant opinion.
However, if a person performed tawaf and then performed an obligatory prayer, does it avail him of performing the two rak‘ahs of tawaf? Scholars differed in this regard. It was narrated on the authority of some predecessors—which is also the opinion of the Hanbali and the Shaafi‘i scholars—that it avails him. Maalik, Abu Haneefah and (one of the opinions of) Ahmad pointed out that the obligatory prayer does not avail him and he should pray the two rak‘ahs of tawaf after the obligatory prayer because they are an act of the Sunnah. The second opinion is the preponderant one because these two rak‘ahs are subordinate to the ritual of tawaf. Given the fact that the obligatory prayer does not count as a valid substitute for them, then it is more logical that a non-obligatory prayer also does not.
The two rak‘ahs of tawaf may be prayed at times of prohibition. People who were reported to have performed tawaf after the Fajr prayer and then performed two rak‘ahs include Ibn ‘Umar, Ibn Az-Zubayr, ‘Ataa’, Taawoos, Ibn ‘Abbaas, Al-Hasan, Al-Husayn and others. This is the view of the Hanbali and the Shaafi‘i scholars. It is the preponderant opinion, contrary to that of Abu Haneefah and Maalik, who prohibited praying these two rak‘ahs at times of prohibition. They used the generality of the texts that indicate the prohibition of offering prayers at those times as evidence.
Allah Knows best.