How can I programmatically unselect "View published content" checkbox for anonymous users?
You have to insert this code in a hook_install() or hook_update() :

$role = \Drupal\user\Entity\Role::load('anonymous');
$role-&gt;revokePermission('your_permission');
$role-&gt;save();