If you create a site template by saving an existing site as template from site settings, it creates a user solution in the site collection and automatically activates it. You can then go ahead and create sites based on this template. If for any reason you delete the site created from the template and if the user solution was still active in site collection settings, then we will not be able to deactivate the solution at all. This leaves an orphaned solution in the site collection. There is no permanent fix for this problem at the moment. One workaround is to restore the deleted site from recycle bin and then deactivate the solution after which you can delete the site.
When you try to create a site template you are presented with the below error and the spinning processing icon,
InvalidOperationException: Error generating solution files in temporary directory.
ULS Logs error : List does not exist.
This situation occurs if you had enabled SharePoint Publishing feature on the site at one point in time before and then deactivated it later to save the site as template. The deactivation leaves references to some SharePoint internal lists but the lists themselves get deleted (My assumption). Hence you will not be able to create a template from such a site. Also, please note that this situation is not consistent, i.e. in some cases you are able to create site templates from a site which had SharePoint Publishing feature enabled previously.
If you google this error, you will notice that people talking about insufficient permissions on the temporary directory on the front-ends etc. Just to be sure that it is not the case make sure that you can create site templates from other sites in the same site collection or different site collections in the farm.
As a workaround you can recreate the source site artifacts for a clean template either manually or using powershell / custom code.