Normally, a diptote takes fatḥa in the genitive when it lacks «ال» and is not a muḍāf: «فِي مَسَاجِدَ».
But with the definite article, or when the noun is the first term of an iḍāfa, genitive kasra returns:
فِي الْمَسَاجِدِ — in the mosques.
فِي مَسَاجِدِ الْمَدِينَةِ — in the city’s mosques.
This is a further grammatical qualification beyond the short core passage being taught.