Why do you think he was demoted?
This seems to be another example of something fans seem to view as ‘canon’ but isn’t actually consistent with what was onscreen. A kind of ‘Mandela-effect’ headcanon.
In TOS, M’Benga was specifically asked by McCoy to come aboard and act for him as CMO while he was away. Asking a former CMO to come back, shadow you for a short period and then act for you makes a lot of sense when there are members of the crew of other or mixed species.
It was quite clear that M’Benga was in transition towards a Chief Medical Officer post on a Station. That would suggest M’Benga already had the rank and was qualified for the job.
Meta-wise, this was actually another one of Roddenberry’s backdoor pilots, this time for a Starfleet medical show based on a station.
Episodes 6 & 8 are where long time fans usually fall in love with the show. Many of us find it the Trekiest thing ever.
But it very deliberately takes its time to get there. It’s like the lobster in the pot of hot water trick for kids formed with SW and other 3D kids animation. By the time they get to the end of the first half of season one, they’re fully into Star Trek, but without culture shock.