Well, they sold because they were good one way or another. You are just thinking of one particular way a book can be considered "good" and disregarding the rest
I think there are a lot of factors that go into selling books beyond the quality of the writing. Timing is huge - a really well-written book about teen mermaids probably isn't going to sell if another book about teen mermaids has just bombed. A really well-written book about a subject an editor cares about has a better chance than an equally well-written book about a subject the editor doesn't care about. Sometimes books take off because the right influencers picked them up at the right time. etc. I agree that there are countless ways to measure whether books are "good", but I also think there are lots of factors beyond the book itself that influence sales.