I've been on AH for a number of years now and have seen references to some mildly popular books. However, I've also seen references to what appear to be very niche books where I suspect the prints number in the single-digit thousands. Maybe some of these are used as ancillary texts in history courses, which could boost their numbers, but most of them are certainly nowhere near the New York Times Best Sellers lists (and, frankly, those that do make that list rarely make the suggested reading lists here).
Unfortunately, I haven't been keeping notes for actual titles, but some semi-realistic example titles might be The Evolution of English Frigates from 1650 to 1832 or Dutch Politics During the Eighty Years' War. For certain corners, these are very important topics, but I struggle to understand the economics of an entire book versus a series of papers.
I ask this in comparison to papers, which are conventionally much shorter but, of course, tend to focus on more narrow questions. Looking at the above pseudo-titles, some papers might include "Evolution of structural frames in English frigates from 1650 to 1700" or "Gradual Catholicism: How Alexander Farese blunted the Spanish efforts to hold The Netherlands." (These are taken from Wikipedia entries but seem realistic.)
What makes an historian sit down and write an entire book, and a publisher agree to put ink to paper, for what appear to be very narrow topics? Is the historical book market bigger than it seems, do publishers take the risk on narrow or negative margins, or is there some other factor involved?
The answer to this is very simple: the doctoral title. Doctoral programs worldwide require the writing of a book-long thesis on what is typically a very niche topic. Many countries require the publication of such a thesis in some form, and typically, the doctoral candidate needs to pay from their own money for publication (usually costing about 2500 euros and more depending on publisher). In rare cases, a very good thesis (one that is graded as magna or summa cum laude) can find means to get sponsored. But, well, this is the principal answer why we have so many books on niche topics.
If the rules would change and permit us to write accumulatively, like natural science students tend to do, we'd probably rather produce a series of papers on related topics, but we have to write a monography.