$node->set('uid', 0); $node->save should have worked. Maybe you forgot to flush caches.
To programmatically set the author to anonymous user on any entity you can call $entitiy->setOwnerId(0); and then $entity->save();, done.
user_cancel() is run in a batch. This means that either it's called in a form, or batch_process() needs to be called after it. For example, this is the code used from UserController::confirmCancel().
$edit = [
'user_cancel_notify' => isset($account_data['cancel_notify']) ? $account_data['cancel_notify'] : $this->config('user.settings')->get('...