Entities are powered by the plugin system in Drupal, which means that there is a plugin manager. The default \Drupal\Core\Entity\EntityTypeManager provides discovery and handling of entities. The \Drupal\Core\Entity\EntityTypeManagerInterface specifies a getRouteProviders method that is expected to return an array of strings that provide the fully qualified class name of an implementation of the \Drupal\Core\Entity\Routing\EntityRouteProviderInterface interface.
There is an event subscriber defined in core.services.yml called the entity_route_subscriber. This service subscribes to the dynamic route event. When this happens, it uses the entity type manager to retrieve all entity type implementations, which provide route subscribers. It then aggregates all the \Symfony\Component\Routing\RouteCollection instances received and merges them into the main route collection for the system.