How do I unlock a field?
You need to load the related field storage config entity and change the locked status:

\Drupal::entityTypeManager()
  -&gt;getStorage('field_storage_config')
  -&gt;load('node.field_foo')
  -&gt;setLocked(FALSE)
  -&gt;save();


This is just an example - you should inject the entity type manager instead of calling the global version if contexts allows.