The easiest is to just set the metadata for the node.
node.set_meta("_edit_lock_", true)
to lock it.
node.set_meta("_edit_lock_", null)
to unlock it.
There is a more complicated/hacky method involving finding the unlock and lock buttons and emitting their button pushed signal after making a temporary selection with the editor selection class.