Start by updating your iPad to the most recent version of iPadOS - at the time of writing, this being iPadOS 26.3 - and then test your Pencil with the iPad.
If the problem is unresolved, pairing and testing your Apple Pencil with another compatible iPad is recommended - as this test establishes if the Pencil itself is serviceable...
If the Pencil doesn't pair with another compatible iPad, you will have demonstrated that the Pencil itself is defective. By contrast, successful pairing and operation shows that the Pencil is functional; any issues will therefore be with the original iPad, or potentially a pairing problem between the Pencil and the previously-paired iPad.
I have myself experienced one occasion when my Pencil would not successfully re-pair with its host iPad following a system software update. Pairing the Pencil with another compatible iPad resolved the pairing-deadlock that was preventing the Pencil from working with the original host iPad.