You would never use a real pen to write on your iPad but the iPad Pen provides the comforting, nostalgic feel of using an actual ink-filled writing instrument without really putting ink on your screen.
As for Pencil, the magic comes courtesy of some clever electronics. Where most iPad pens have been passive devices, relying on simple conductive tips that basically trick your iPad into thinking they’re a finger, Pencil is what’s referred to as an active stylus. Both ends are essentially highly-sensitive buttons. Inside both the tip and eraser are 14k gold-plated switches; Bluetooth guts instantaneously tell your iPad when one is being depressed. What that means in practice is that you don’t have to press anything or change any settings to switch between drawing and erasing. You just flip the thing around.