Pencil battery issues, brought about by inconsistent battery charging and management, are often seen as the primary suspect. In your case, I don’t believe this to be the likely culprit...
You indicate that charging is consistent when using the in-line charging adapter with your Power Adapter, but is unreliable when connected to your iPad. This might reasonably suggest that the Pencil battery itself if healthy - but something else is causing an issue.
The Lightning connector on your Apple Pencil is double sided - each side of the connector being duplicated but otherwise independent of the other; this permits the Pencil (or other Lightning connector) to be connected in either orientation. By comparison, the iPad only has matching connector pins on one side of the socket.
Perhaps experiment with your Pencil, visibly marking the body of the Pencil to identify the two different sides of the Lightning connector blade - and attempt to identify charging deficiencies in one or other orientation. It is possible that the connections on one side of the “blade” are dirty/contaminated and causing an connection issue.
I hope this proves to be helpful in identifying the potential cause of the problem.