How to change the site logo in a preprocess function?
How to change the site logo in .theme preprocess function?

The site logo is no longer in the page template. You can change it now in the branding block:

function mytheme_preprocess_block(&amp;$variables) {
  if ($variables['base_plugin_id'] == 'system_branding_block') {
    $variables['site_logo'] = '/newlogo.jpg';
  }
}


Caching

You mentioned you want to change the logo based on URL args. This would be difficult to do this in the system branding block, because the template is not rendering the render array, but transferring only the content of three variables and so any attempt to add cache meta data would be useless.

You have two options. Implement your own site logo block plugin in a module or use this theming only solution:


disable the site logo in the branding block
set a variable with the url for the logo in page preprocess $variables['logo']
add your own markup to the page twig to output the site logo


page.html.twig:

&lt;a href="{{ path('&lt;front&gt;') }}" title="{{ 'Home'|t }}"&gt;
   &lt;img src="{{ logo }}" alt="{{ 'Home'|t }}" /&gt;
&lt;/a&gt;


By doing this in the page template you avoid caching problems because the page is already cached for each url separately.