It is a sunnah to perform two rak`ahs of Prayer behind maqam Ibrahim, because the Prophet (peace and blessings be upon him) did so. It is also proved by the Qur’anic verse that reads: (And when We made the House (at Makkah) a resort for mankind and a sanctuary, (saying): Take as your place of worship the place where Abraham stood (to pray)…) (Al-Baqarah 2:125)
A pilgrim is to perform two rak`ahs of Prayer behind maqam Ibrahim, meaning that the maqam is between him and the Ka`bah. If the pilgrim cannot pray exactly behind the maqam, then he can pray at any place in the mosque behind maqam Ibrahim. If this is not possible, then he can perform them at any place in the mosque.
If the pilgrim wishes to perform these two rak`ahs outside the mosque, it will be different from the sunnah, but there is nothing wrong in it, as `Umar ibn Al-Khattab (may Allah be pleased with him) did it. He made Tawaf after Fajr Prayer, as reported in Malik’s Muwatta’, and he postponed the two rak`ahs following Tawaf until sunrise. Then he performed them at Dhi Tuwa, a valley known as Wadi Al-Muthallath or Az-Zahir. That valley is outside the mosque, but it is within the borderlines of the Sacred Area.