Age is the first factor. A tank-style water heater typically runs eight to twelve years before the tank itself starts to fail, and once it is leaking at the tank rather than a fitting, a repair is not really an option.
Rust-colored water, a tank that is visibly corroding at the base, or a unit that has needed more than one repair in the last year or two are the signs that point toward replacement being the more sensible spend.
A newer unit with a specific problem, a bad thermostat, a failed heating element, a faulty valve, is usually worth repairing rather than replacing, and that gets said honestly rather than defaulted to the bigger job.
The comparison usually comes down to a straightforward question: does the cost of one more repair, weighed against the unit’s remaining expected life, still make sense, or does that money go further toward a new unit that starts the clock over.