You can try the below code to update the theme on runtime in Magento 2.

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $objectManager->get(\Magento\Framework\View\DesignInterface::class)->setDesignTheme('Magento/luma', 'frontend'); //where Magento/luma is the theme name.

However, you can use the dependency injection in your custom module instead of the `$objectManager`.

Hope it will help!!!