Why is al-ẓālim masculine although al-qaryah is feminine?

The Tawābiʿ and Naʿt: Direct and Relational Attributes