Because الْمَسَاجِدِ has genitive kasrah, it must also take tanwīn.

Restoring Declension: Indefinite Names, Al- and Iḍāfah