If a user has overridden a preference globally, then any attempts to set the preference using the API would fail.
The solution is to either set a local override for that wiki for the preference or set the global preference for the user.
Local override acts as an exception to the global preference value on a per-wiki basis.
Global preference is set across all projects.
GlobalPrefs APIs are documented here: https://www.mediawiki.org/wiki/Extension:GlobalPreferences/API