Shalom from Jerusalem!
It says in megillah 18a
Top rashi
That the order of the geulah is that the beis hamikdash will be built then beis david will come.
According to the rambam in hilchos shoftim beis david is supposed to build the beis hamikdash!
Thank you
Rashi in Sukah 49a says that the Beis ha'Mikdash will come down from Shamayim and will not be built by a person. Therefore, Rashi sees the Beis ha'Mikdash as preceding Mashi'ach. However, the Rambam sees the Mashi'ach as preceding the Beis ha'Mikdash and therefore says the order in his way.
The text of the Shemoneh Esreh would appear to follow Rashi's view, since we say the blessing of Binyan Yerushalayim before the blessing of Malchus Beis David, and we ask Hash-m to build the Binyan.
Yoel Domb