How can they tell if it’s an Class M planet?
They can tell whether or not it's in the so-called "habitable zone." If not, it's not going to be able to support life as we know it.
They'll also, now with Webb, often be able to determine its atmospheric components. If it's 100% gaseous sulphuric acid, it won't be a good candidate for Class M categorization.
But if it's rocky, got a lot of nitrogen, oxygen, water and is in the habitable zone... BINGO, automatic Class M planet. Now, does it have life? That's another question and will get a lot of attention.