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.
It is reported in Musnad Imam Ahmad (book of Hadeeth) and Al-Mu'jam book of At-Tabarani from Anas in a Marfoo' Hadeeth (A Hadeeth that is directly attributed to the Prophet, sallallaahu ‘alayhi wasallam): “Whoever performs forty times of prayer in my mosque (i.e. the Prophet's mosque) with the congregation of the mosque, a statement of being exempt of Hellfire and a salvation from its torture will be written to him/her, and he/she is considered free from hypocrisy.” Al-Haythami said: “Its narrators are trustworthy.”
Al-Munthiri added in At-Targheeb book: “It is reported by Ahmad and its narrators are those of the sound Hadeeth.”
At-Tirmithi narrated this Hadeeth with another wording. Al-Albani said: “There is some defect in it and Nabit ibn ‘Umar is unknown and there is weakness in the Hadeeth.” Shaykh Naseeb Ar-Rifaa'i said: “It is sound.”
Anyway, since such a matter is from among the meritorious deeds, then there is no problem even though it is weak according to Imam Ahmad .
A group of scholars believe that if an action is legalized based on a legal evidence (Hadeeth) that is not false, the reward - Allah willing – will be true. So, it is advisable to act according to such a Hadeeth.
For more benefit on the reward for praying in the two Holy Mosques, please refer to Fataawa 190553 and 88852.
Allah knows best.