I have struggled with this as well, because it is a custom attribute you need to load 2 models in your constructor:
protected $_customer;
protected $_customerFactory;
public function __construct(
\Magento\Customer\Model\Customer $customer,
\Magento\Customer\Model\ResourceModel\CustomerFactory
){
$this->_customer = $customer;
$this->_customerFactory = $customerFactory;
}
public function updateCustomerAttribute($customerId)
{
$customAttribute = 'your_custom_attribute_goes_here';
$customAttributeValue = 'your_custom_attribute_value_goes_here';
$customermodel = $this->_customer;
$customer = $customermodel->load(customerId);
$customerData = $customermodel->getDataModel();
$customerData->setId($customerId);
$customerData->setCustomAttribute($customAttribute, $customAttributeValue);
$customermodel->updateData($customerData);
$customerResource = $this->_customerFactory->create();
$customerResource->saveAttribute($customermodel, $customAttribute);
}
I have tested this personally and it worked after a lot of hours of research and testing.