مَرَرْتُ بِمَسَاجِدَ
Translation: I passed by mosques. مَسَاجِدَ is genitive with fatḥa.
مَرَرْتُ بِالْمَسَاجِدِ
Translation: I passed by the mosques. الْمَسَاجِدِ is genitive with kasra.
Adding the definite article al- allows kasra here. The syntactic case remains genitive; only the case marker changes.