Scotty illegally beaming aboard the ship (which he was never assigned to) and becoming Chief Engineer of it is even worse. Where was the actually assigned CE? Why was Scotty more qualified than that CE?
And Chekov switches department and job. Scotty didn't have a replacement? Who replaced Chekov? Is Chekov's whiz so wasted in his Navigator duties that everyone can replace him? But he is the only one able to replace Scotty in engineering?
CE Olsen was flash fried on the Romulan drill platform. He was no longer "available". Acting Captain Kirk made Scotty CE when he took command. As a Lt. Commander, I'm sure Scott was the ranking Engineer on board no matter how he got there.
Favoritism. Just like when LaForge became CE in TNG, even though the Enterprise was shown to have an abundance of engineers ranking him. Chekov was replace by the bald lady. To my knowledge she's the only one who has.