It's the feminine because it refers to the family, and "família" is feminine. e.g. "João Ferreira" would be "John, [of the] blacksmith [family]". That's also the reason a few surnames include de/da/do (of/of the).
A bit of googling gives me the explanation of "ferreira" being an old word for "iron mine", which to be honest is coherent with modern portuguese forms like "pedreira", toponymics ("ferreira" is a common place name), and the way names come about (João da Ferreira would own or work in the iron mine, or just come from one of the villages where there was an iron mine).