Under Morgan-Keenan classification stellar classes are called O, B, A, F, G, K, M, but what is the logic behind these letters? I can't see any pattern and I doubt they have just been chosen randomly. I also wasn't able to find an answer on the Internet, so is there any reason stellar classes are called this way?
It seems like these letters are inherited from Draper classification system, which used letters to subdivide classes defined by Secchi. Secchi classification uses numbers I to V, while Draper did use letters in alphabet in order. Some of the letters got dropped, and classes reordered later to match physical features (temperature / spectrum) better.
I believe Secchi and Draper added categories as new types of stars were discovered (eg carbon stars and Wolff-Rayet stars seem to be added later), and thus the categorization did not remain as logical as it could've been had it been designed with full knowledge from scratch. Modern system wanted to retain (some of the) existing labels but order them based on some physical feature.
Wikipedia article seems to have pretty decent details on this too: https://en.wikipedia.org/wiki/Stellar_classification