The clever bit is to get a lockfile test and creation (if needed) to be atomic, that is done without interruption. The set -C stops a redirection from overwritting a file. The : > touches a file. In combination, the effect is, when the lock file exists, the redirection fails and exits with an error. If it does not exist, the redirection creates the lock file and exits without an error.
The final part is to make sure that the lockfile is cleaned up. To makes sure it is removed even if the script is terminated with a ctrl-c, a trap is used. Simply, when the script exits, the trap is run and the lock file is deleted.