If a resource-using unit is deleted or killed (or promoted to a new unit that doesn’t use that same resource), the resource associated with that unit is freed up. But with 2 iron, you can only have 2 iron-using units at a given time. Note also that if the iron mine is pillaged (or conquered by another Civ), you will still have the 2 swordsmen, but they will operate as resource-deprived (combat strength malus and won’t heal) until you repair the pillaged mine (and start getting 2 iron again) or otherwise find some replacement iron.
The longer-term solution is to go out and find more iron — trade for some iron, found a new city near some on-map iron that isn’t already owned, cultivate alliances with city-states that have iron, and conquer other civs’ iron-bearing cities.