programmatically enable and disable theme from update hook
Use the theme installer service to enable and disable themes .

Install a list of themes:

\Drupal::service('theme_installer')-&gt;install(['mytheme']);


Uninstall a list of themes:

\Drupal::service('theme_installer')-&gt;uninstall(['mytheme']);


Reference: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension%21ThemeInstaller.php/function/ThemeInstaller%3A%3Ainstall/8.2.x

Instead of writing to the config you can use the theme handler to set a default theme:

\Drupal::service('theme_handler')-&gt;setDefault('mytheme');