This is most likely because when the battery went dead, if you don’t get it on the charger soon, then the battery gets too drained to be able to take a charge anymore. This usually happens when the battery gets drained all the way and then goes too long without getting charged, or just sits for a long time even when the battery still has a decent charge and there is still draw from the battery by the pencil and the battery gets too low. These batteries are usually kept safe by the device turning off and shutting down before the batteries get too low, however, even when the device shuts off, it can still draw some power as well as the batteries just naturally lose charge when they aren’t being used over time.
If the pencil is still under warranty you can take it to an Apple Store or get in touch with Apple Customer Service and see if they can do something for you. There is no guarantee that they will, but it is worth a try.