That was the conclusion I came to, that there was some other permissions check going on for moodle/site:config, but what confused me is there are quite a few historical forum posts (not too old, 2018 ish) asking same thing and the above code seemed to work for them. Perhaps something has changed in Moodle since then.
General developer forum
Give capability x access to local plugin settings page
This discussion has been locked so you can no longer reply to it.