It's there to prevent the firing pin shooting loose under gas pressure and back into the buffer face.
The firing pin retaining pin is a hardened steel pin, because its job is to keep that pin in the carrier when the gas pressure comes swooshing into your bolt carrier, causing the rather violent and powerful expansion of the bolt/bolt carrier unit and starting the process of unlocking and cycling the action. The gas rings on the bolt provide the front seal on this piston, while the firing pin collar provides the back seal. The hammer holds the firing pin tight against the back of the carrier during the initial unlock cycle, but there can still be quite a bit of pressure within the bolt/carrier assembly when the hammer's cocked down off the firing pin by the carrier, and without the firing pin retaining pin, it would shoot out like a backwards blowgun dart.