In «مَرَرْتُ بِمَسَاجِدَ», masājid is an accusative direct object.

Diptote Causes — Ultimate Broken-Plural Patterns