Images break with wrong href; clearing caches fixes!
More than likely, your server is responding to multiple domain names, either by being the default or matching/wildcards for ServerName and ServerAlias (using Apache terminology here; nginx and IIS have similar concepts).

So, the problem is that you get a request to www.example.com, and Drupal serves that page up and uses that URL as the base.  It will also respond to www.subdomain.example.com and use that as the URL base.  The problem you see is that the subdomain request is the one being cached, and the hostname isn't part of the cache ID.

The general solution to this is to set up a canonical redirect in either the Apache config or the .htaccess file for your site (I prefer in server config).  The rule would look something like this

&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
  RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
&lt;/IfModule&gt;


When you do that, Apache will redirect everything to https://www.example.com.  Over time, Google will fix its indexes because of the 301 redirect, or you can try to submit manual delists.