The Factory allows advanced units to be produced, and it can be built in the Enlightenment Age. Research needs to be carried out at the Blacksmith to upgrade Factory units. Factory units share the same troops capacity as Barracks Units that can be increased following the Barracks upgrade or Standing ArmyTechnology research.
Constructing the 2nd Factory at Global Age also won't add Troops Capacity but will provide another production line for Factory. Each Factory can only produce units type up to its own building level. But the level of the units type, always refer to the last unit's upgrade at the Armory.
Researching ResistanceTechnology Chapter 4 in the Library will make the Factory produce Heavy Tanks on defense when destroyed. The troops level will depend on the highest Bunker Defenders level.
Upgrading the Factory unlocks new factory troop upgrades; while upgrading the Armory building is not required to upgrade them (e.g., an Atomic Age Armory can upgrade Digital Age troops if the base has one Digital Factory).