How do academics find time to write books? Books covering primarily academic topics, from philosophy and neuroscience to physics and geopolitics, are usually written (not surprisingly) by experts in the field, which are normally academics themselves. I wonder how these academics secure the time and funding to write such books?

To give a few arbitrary examples, I refer to books like these (note that these are not college textbooks):


Nihil Unbound: Enlightenment and Extinction - at the time of publication, the author was an associate professor of philosophy;
Phi: A Voyage from the Brain to the Soul - the author is a professor of psychiatry at the University of Wisconsin;
Incomplete Nature: How Mind Emerged from Matter - the author is a professor of biological anthropology;
The Global Minotaur: America, Europe and the Future of the Global Economy - the author is a professor of economics.


Is this something academics normally work on in their spare time, or do they get paid to actually do it? Are there grants or donations involved? Is it a privilege that comes with tenure? I'm mostly familiar with life science research, where people will constantly publish papers in journals and that's it - there seems to be no time nor funding to write anything beyond that, at least not as a part of the job.

Apparently, the amount of books written by academics also varies with discipline - e.g. there are more books by professors of philosophy compared to professors of physics. Is this also due to the differences in funding mechanisms and day-to-day job duties among various disciplines?

What are the main factors that influence this?
I'm an associate professor in a humanistic social science (anthropology). Anthropology is different from pure humanities in that monographs are usually based on extended participant-observation fieldwork.

Before getting tenure, I wrote two books (monographs):


The first book was an extension of my original PhD dissertation. I revised and submitted it to academic presses in the first three years of my first tenure-track job. I used a portion of my third year leave to do the final editing of the ms. 
I used the remaining half of my third-year leave to do some of the research for my second book. I also changed universities and used another year of leave provided by them for additional fieldwork. The second book was then written during summers and other leave periods. 


So in the twelve years  or so years since my doctorate, I've finished two books. I'm currently working on my third using a portion of my triennial leave to focus on writing it. Each book has taken around 4-6 years to research and write -- which is on the fast side compared to some of my peers. I should note that one of my senior colleagues in history has written a book every two years -- he is considered exceptional by most. 

To answer some of your specific questions:


  Is this something academics normally work on in their spare time, or do they get paid to actually do it? 


Writing books (for faculty in the humanities / humanistic social sciences) is considered part of our research output -- the same as when natural scientists write journal articles. We try to do secondary research and write during the school year and do our primary field research in the summers and when we can get research leaves (sabbaticals, triennials, etc.). 


  Are there grants or donations involved? 


I used external grants to conduct the field research for the books. I also used internal grants for book completion (copyright clearances, indexing, production offsets, etc.).

It should be noted that the royalties for most academic books (except popular textbooks) are very modest.  At best, you might earn a few thousand (US) dollars on royalties on an academic book. Many don't make any money at all. Advances on books are also very rare. 


  Is it a privilege that comes with tenure?


No. If you want tenure, you have to write. At most R1s, you have to have at least one monograph for a strong tenure bid (in humanities/humanistic social sciences). 


  I'm mostly familiar with life science research, where people will constantly publish papers in journals and that's it - there seems to be no time nor funding to write anything beyond that, at least not as a part of the job.


In disciplines where monographs are important, journal articles are slightly deprecated in importance. 

Note that monographs are also separate from edited volumes. In disciplines where "books" are prioritized, this almost always means a single-authored monograph from an academic press. Edited volumes count much less in value in terms of promotion and merit raises.