A bad book wouldn't make money, because no-one would want to read it.
I think the OP's question is based on a rather inaccurate understanding of the writing/publishing process, and also the artistic process.
Consider this: The vast majority of people who start out to write a book fail. Of that tiny minority who succeed, most never get their book seen and accepted by a publisher. Of that minority who do get seen and accepted, most never get stocked and displayed by the mainstream bookshops. Of that minority who do, most never become best-sellers.
So the question should not be whether to write a commercial success, or a slow-burning literery masterpiece, but just to fucking write, and may God's best luck be with you because you'll need it. The idea that the writer has a choice in this is daft.
I imagine that a 'bad book' is not one in which the spelling is appalling, or the plot disappears into nothingness, or the binding doesn't stay true, or the protagonist changes their motivations part way through a propos of nothing; all these inconsistencies would be picked up by editors and printers.
By 'bad book' I imagine you're invoking this rather unfair and snobbish delineation between literary novels (which still in some quarters are seen as 'real writing') and genre fiction such as spy books, or hard-boiled detective stories, or gory horror, or tell-all emotional novels of childhood despair which publish straight into paperback and don't get reviewed on the late night shows from New York and London which we like to watch because they make us feel suitably cultured.
The fact is that genre fiction outsells literary fiction by many orders of magnitude, and it does this because it is supremely GOOD at what it does. It hits exactly the buttons that readers want hitting.
No writer who finishes a novel or any worth (and notice I say, of any worth) can have done so solely with the cynical intention of writing a commercial success. Of course they hope it will be, but first they have to understand the genre, subvert the genre if they wish, and pass muster with all the highly attuned readers of that genre, who won't take any old pap. You cannot fake it, and the idea that you can 'fake write' a sucessful commercial novel, and then turn to 'proper' writing' which doesn't sell as much but which ticks many academic boxes is proposterous. As a myth, it also prevents many good genre writers from feeling proud about the novels they write, when they deserve to feel very proud indeed.
Fantastic fiction is what readers want. If you can write it, and write it supremely well, then you will sell. Millions.
Stephen King is not a literary master. He is no Flaubert, Camus or Dostoevsky - but he his an arch storyteller who kicks arse within his genres. Most writers would kill to be Stephen King, and have his readership. In this competitive, harsh and ultimately unrewarding publishing climate, to separate writers into worthy and unworthy based on elitist assumptions of what makes good or bad art is wholly unfair.
*Glares at everyone, including self*