Yes, leaving aside the theological issue of naming churches for saints which is irrelevant to this conversation, St Mary's is simply an alternative short hand way of saying "The Church of St Mary," the 'of' indicating the genitive case. As others have pointed out, the genitive means more than the possessive. It doesn't mean St Bernard or St Harry OWN the church, but that the church is dedicated especially to them, or named after them.

So the use of the apostrophe in those cases IS grammatically correct IMO.