Your question is a very interesting one and very wide in scope to answer. In my opinion, I think you need to narrow it down to get precise answers. Book production goes through different stages from reviews, editing, graphic designs, formatting, publishing, marketing etc. At every stage, a paid specialist takes care of it. They purchase license, pay membership dues to different organization, databases, pay subscription fees to plugins and packages like plagiarism checkers and many others. You may try inquiring the cost of some of these to get clue. They rely heavily on marketing to sell and offset the cost of publishing a book. Books which they feel will not yield out it's cost of production are usually declined during proposals irrespective they need such titles to bulk up their book collections or they may charge you based on expenses made and make your book open access. Many more factors still involved.