How change user form mode programmatically?
something like this:

/**
 * Implements hook_entity_type_alter().
 */
function YOUR_MODULE_entity_type_alter(array &amp;$entity_types) {
  // We get all form modes, for all entities, and loop through them.
  $form_modes = \Drupal::service('entity_display.repository')-&gt;getAllFormModes();
  foreach ($form_modes as $entity_type =&gt; $display_modes) {
    if ($entity_type !== 'user') {
      // We are only interested in adding a handler to the Node entity.
      continue;
    }

    $user_entity = $entity_types[$entity_type];
    foreach ($display_modes as $machine_name =&gt; $form_display) {
      if ($machine_name !== 'sinscrire') {
        // We are only interested in adding this form mode to the definition.
        continue;
      }
      // We get the default handler class. It will be enough for us.
      $default_handler_class = $user_entity-&gt;getHandlerClasses()['form']['default'];
      // We set the form class, keyed by the machine name of our custom form mode.
      $user_entity-&gt;setFormClass($machine_name, $default_handler_class);
    }
  }
}


Credit goes here: https://www.webomelette.com/render-custom-entity-form-modes-programatically-drupal-8