The Origin of "Class M" in Star Trek
The term 'M-class planet', used throughout the Star Trek franchise to describe Earth-like worlds, originated with the Vulcan classification 'Minshara Class', as revealed in the Star Trek: Enterprise episode 'Strange New World'.
A Vulcan Standard
The episode 'Strange New World' (Star Trek: Enterprise) depicts an early Starfleet mission where crew members hallucinate due to pollen on an alien planet. During the episode, it is explained that the 'M' in 'Class M' stands for 'Minshara Class', a term used by Vulcan explorers for Earth-like planets.
Adoption by Starfleet
Captain Archer's Enterprise was the first Starfleet vessel to adopt this terminology, which later became standard across all of Starfleet.
An Unanswered Detail
In The Next Generation, four sub-levels of M-class planets were mentioned, but their specific meanings have not been confirmed by the franchise.