Most of the large rocky bodies in the solar system display evidence of past and/or current magnetic activity, driven by thermochemical convection in an electrically conducting fluid layer. The discovery of a large number of extrasolar planets motivates the search for magnetic fields beyond the solar system. While current observations are limited to providing planetary radii and minimum masses, studying the evolution of exoplanets' magnetic fields and their interaction with the atmosphere can open new avenues for constraining interior properties from future atmospheric observations. Here, we investigate the evolution of massive rocky planets (0.8 − 2 MEarth) with different bulk and mantle iron contents. Starting from their temperature profiles after accretion, we determine the structure of the core and model its subsequent thermal and magnetic evolution over 5 Gyr. We find that the planetary iron inventory and distribution strongly affect core structure, evolution, and the lifetime of a magnetic field. Planets with large bulk and mantle iron contents tend to feature large solid inner cores, which can grow up to the liquid outer core radius, shutting down any pre-existing magnetic activity. Consequently, the longest dynamo lifetimes (∼ 4.25 Gyr) are obtained for massive planets with intermediate iron inventories. The smaller inner core radii and the chemical buoyancy fluxes introduced by the presence of light impurities can extend the magnetic field lifetimes to more than 5 Gyr. While the calculated magnetic fields are too weak to be detected by ground facilities, indirect observations may provide valuable insights into exoplanetary dynamos.