Let me explain what happened. A battery shouldn't be drained to 0%. A battery shouldn't be kept at 100%. It seems like you have been charging it from 0% to 100% in one go. That's probably the worst thing you can do to a battery. Your phone is also a few years old now. Assuming you have done this a lot, you have degraded the battery so it cannot hold a charge correctly anymore. That error is saying your battery needs replacing as it has degraded.
Battery health tips: charge before 20%, stop at 80%, or use the health management settings to safely use 100%. Don't do a single giant charge with fast charging on. If possible, use a routine to disable fast charging overnight and let it slow charge as you sleep.