رَأَيْتُ مَسَاجِدَ: direct object — accusative; fatḥa marks the accusative.
مَرَرْتُ بِمَسَاجِدَ: after a preposition — genitive; fatḥa marks the genitive.
The visible vowel is identical, but the syntactic case differs. Always use the governing ʿāmil to identify the case.