Code is generated when the Magento application cannot find a class when executing code.
A Factory class creates instances of a type. See Instantiating objects with factories for more information. Factories are directly referenced within application code.
You can designate a Proxy to be generated for a type in order to ensure the type is not instantiated until it is needed. See Proxies for more information. Proxies are directly referenced within DI configuration.
Interceptor classes are automatically generated to facilitate Magento’s plugin system. An interceptor class extends a type and is returned by the Object Manager to allow multiple plugin classes to inject logic into different methods. Interceptors work behind the scenes and are not directly referenced in application code.
Why should you regenerate code?
Suppose a Customer or Proxy class for a Customer class is generated and the Customer class has new methods added to it. Because a Customer or Proxy exists on the file system, it is not regenerated. However, the Customer or Proxy implementation is incomplete now because it does not have the new methods. In this case, you must regenerate the Customer or Proxy class.
If the code generator implementation itself is changed, you must regenerate all the classes. This is rare, however.