Those pins might be connected to something that could do Bad Things if fiddled with at the wrong time. It's a safety feature which limits the effect of software bugs and hardware glitches, hopefully preventing the device from damaging equipment or killing people when it misoperates.
To be clear - the lock function works on the port's configuration bits, not the output data or set/reset registers. So locking a pin doesn't prevent it from being used, but does prevent it from being changed from one configuration/mode to another. So for example if a pin is set to be a push-pull output, after locking the configuration it can't accidentally be set to eg. analog input mode.
This feature makes sense because usually once a GPIO port pin has been set up (to match the external hardware) it won't be changed again (until Reset, when all pins are set back to floating input mode).