Age is the single biggest factor: most tank water heaters are built to last roughly eight to twelve years, and a unit past that mark that develops a leak, heats unevenly, or needs a second repair in a short span usually costs more to keep patching than to replace outright. A tank leaking from the tank body itself, rather than a fitting, has almost always already started to corrode from the inside and is not a candidate for repair.
Replacement is also the right moment to correct sizing: a tank installed for a smaller household, or one that has never quite kept up during a busy morning, can be swapped for a higher-recovery model that actually matches how the home uses hot water today. For a gas unit, that includes confirming the vent still meets current carbon monoxide safety code, not simply reusing whatever venting the old unit had.