I have a simple one liner for this. It uses System Events to send the default key combo for the Lock Screen command and works in all versions of OSX from High Sierra (10.13) on. Even Mojave! Though it will prompt for additional Security permissions for the App, in the newer OSX versions
tell application "System Events" to keystroke "q" using {control down, command down}