Duh. Apple has a warranty period too. For how many years will Tesla replace the battery for free? Think.
The battery warranty is external to the vehicle warranty. Any battery you buy new, at least in North America, comes with a warranty. The warranty is on that battery.
Let's take a common but low cost case: 2 year full replacement, 1 year prorated replacement. If it fails within 2 years, you get a free replacement. If it fails within 3 but more than 2, you pay a
partial cost of a new battery.
Depending on the warranty terms, these replacements are likely warranted as well (especially the prorated replacements). If the batteries you buy are dying every year, you get free batteries for life. Of course, warranties are designed to be advantageous to the manufacturer while offering consumers a safety net, so it's unlikely that you'll get free batteries for life (because one of those batteries probably
will last beyond the warranty, as they very often do
by design).
The batteries being supplied by Tesla have these warranties too. They are not tied to the vehicle's warranty. Tesla doesn't want OEM batteries to be dying early either; OEM relationships require some reputation and respect so as to not hurt either company involved.
I'm not sure Apple specifically does this, but replacements and repairs are normally under some sort of warranty too even outside the car world.