Edit a config variable of a custom module in controller
With the ConfigFormBase, you need to implement the editableConfigNames() method.  E.g. 

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'example.settings',
    ];
  }


In general, you need to get the editable version of the config file to change it.  ConfigFormBase (well actually, ConfigFormBaseTraits) will only return the editable config is you implement the above method.

For reference, here's how you could do this without the ConfForm logic.

$config = \Drupal::service('config.factory')-&gt;getEditable('example.settings');
$config-&gt;set('message', 'Hi')-&gt;save();


See the documents for details.

Since you are expanding ConfigFormBase, you should be able to use:

$config = $this-&gt;configFactory()-&gt;getEditable('example.settings');


To get the editable version.