Ensure that you have not disabled Bluetooth on your iPad. If Bluetooth is disabled in iPad settings, or from the Control Centre, the Pencil will not work with the iPad.
Assuming that Bluetooth is enabled, all is not lost...
I have myself experienced something similar with the second generation Apple Pencil just once in the last five years. To resolve, you may find that simply pairing your Pencil with another compatible iPad will clear the problem.
As pairing is fully automatic and occurs whenever the Pencil is docked any compatible iPad, the process is easy and transparent. If you don't have immediate access to another compatible iPad, you might visit an Apple iPad retailer that has accessible display models - and dock/test your Pencil with the display iPad. After demonstrating that your Pencil works as expected with another iPad, re-pair the Pencil with your own iPad.
If you remain unable to resolve the problem, be aware that if a Pencil is set-aside for an extended period, unused and uncharged, the Pencil battery may have be damaged through deep discharge. In common with all Li-ion batteries, they must always have some level of charge.
The tiny internal Li-ion battery is susceptible to permanent/irreversible damage through being left discharged for long periods. Even some “new” pencils can exhibit signs of failure out-of-the-box if they are “old stock”.
It is essential that if you have an Apple Pencil that you charge it regularly - whether used or not - so as to protect the battery from deep-discharge. Do not allow a pencil to remain in low-charge state for any period of time - as the internal battery will fail, rendering the Pencil useless. Setting aside an unused Pencil, for extended periods, is a recipe for premature death of the Pencil battery.
If the Pencil Battery has failed, the only remedy is to replace the Pencil. If the battery has failed and your pencil is within its one-year warranty, you should look to having it replaced by your retailer or at an Apple Store.
Genius Bar Reservation and Apple Support Options - Apple
Gentle warming of the Pencil (such as placing on a hot water radiator), prior to attempting charging of the Pencil, can sometimes resurrect a dead Pencil battery.