The Apple Pencil (2nd generation) is not compatible with the iPad Pro (M5), so it will neither pair nor charge when magnetically attached to that iPad.
According to Apple's compatibility documentation, the iPad Pro (M5) supports two Apple Pencil models:
- Apple Pencil Pro: Supports wireless pairing and charging through the magnetic connector.
- Apple Pencil (USB-C): Pairs and charges using a USB-C cable. Its magnetic attachment is for storage only.
You can verify compatibility here: Apple Pencil compatibility - Apple Support
Since you mentioned that your Apple Pencil previously worked with another iPad Pro (M5), I suspect you may actually have an Apple Pencil Pro rather than the 2nd-generation model.