Actually I have three questions but related to one topic.
Why Masjidul Aqsa was the first qibla of Muslims?
Why Prophet pbuh used to offer salah towards Masjidul Aqsa after Hijra to Madina for 17 months?
2) How did prophet know to make it qibla before the Kaaba?
3) Did the Prophet pray towards Al-Aqsa at the order of Allah or at his own decision?
Thank you for writing to us.
Let us not get entangled in the name "first qibla". Let us just say that the Qibla of Bayt ul Maqdas. We know that in Makkah the Muslims offered salah with the Kaaba as their Qibla. When the Muslims emigrated to Madinah, the Almighty instructed the Prophet (sws) to make Baytul Maqdas as the Qibla. It is evident from Aayah 143 of Surah Baqarah:
مَا جَعَلْنَا الْقِبْلَةَ الَّتِي كُنتَ عَلَيْهَا إِلاَّ لِنَعْلَمَ مَن يَتَّبِعُ الرَّسُولَ مِمَّن يَنقَلِبُ عَلَى عَقِبَيْهِ
"And We appointed your former Qiblah (i.e. Baytul Maqdas) only to see who follows the Prophet and who turns away..."
This Aayah and the one before it clarify that this was a temporary directive and was given to test the Ismaelites so that it becomes evident that who among them understands the actual reality and who loses his way by becoming enslaved to the apparent.
The implication of these Aayaat (142 onwards) is that the change of Qiblah for the Ismaelites was a great trial for them but it did not prove difficult for those who were not slaves of their old traditions but were true worshippers of God and had true faith in Him and His Prophet.
The hadith narratives provide more details of the same.
Hope this helps.