This went OK. I had some tangles with incompatible modules, almost surely my fault for doing things wrong. Fixing it was a good way to become more familiar with composer and the Drupal module system!
To get Drupal upgraded I edited the
composer.json file manually to remove the Matomo module, which was a bad idea. I suppose it was using its versioning info to signify that it was not compatible with Drupal 9. So once composer no longer knew that I wanted the Matomo module it was happy to upgrade to Drupal 9. But Drupal's internal config still knew that I had the Matomo module installed. Eventually I figured out how to uninstall with the Matomo module with drush, but only after figuring out a workaround for a bug with the module uninstaller. BTW the Matomo code was no longer in the
modules/contrib folder on my server and composer refused to install it since it was incompatible with the already installed Drupal 9, so I had to manually download the Matomo module code into that folder in order to be able to run the drush command to uninstall the module.