pkg lock is used to lock packages against reinstallation, modification or deletion. pkg unlock unlocks the named packages. Either variant only has an effect on currently installed packages. Consequently it is impossible to block installation of a new package by using this mechanism, unless such an installation implies updating a locked package.
I want to upgrade certain ports only by source because I have nonstandard options.
To avoid that pkg upgrades them I have to lock them. To upgrade via source I have to unlock them and then lock them again?
Just for clarification; I see the OP uses pkg(8). But replies appear to be from the older pkg-tools (pkg-) note the dangling hyphen. It's my understanding, and experience, they're different. Are they somehow the same, in the current context?