I had this issue too, though I’ve had my AirPods for longer at this point. My own diagnosis was that the metal contact inside the case (at the bottom where the stems go into the case) had corroded after years of use, so the AirPod wasn’t making solid contact to be able to charge consistently.
I came up with some hacks worked for a short period of time (e.g., cleaning the port, like the previous poster mentioned, wrapping tie AirPod stem in foil to increase the electrically conductive surface area in hopes that a different part of the metal contact would connect) , but the only long-term solution I could find was to buy a replacement charging case.