When a transaction is locked it can only be spent by the person who can provide an unlocking script. The locking script usually says only the person who has the private key that fits this public key can spend this output. The unlocking script is then simply a proof that the spender is in possession of the correct private key.