While that does occasionally happen, it's definitely not true in general. The people I know who wrote academic books did so by taking a sabbatical from their university job and/or working evenings and weekends for the actual writing. Occasionally they can apply for a separate writing grant to cover their lost salary, but that's completely separate from their day job.
Except in many cases it isn't. Most of the people I know who have written academic books did so off the clock and on their own time. Sure the university let them use their university office and resources, and obviously much of the research the book is based on is research they'd already done as part of their job, but the actual writing time and any additional research they had to finance from sources unrelated to their university job.
However, note that they are very anarchic when it comes to commercial books, not just journal articles!
E.g. from the Sci-Bay search results, this is $131 on amazon.com, and quite possibly the authors do want the royalties.
[BOOK] Intelligent optimisation techniques: genetic algorithms, tabu search, simulated annealing and neural networks D Pham, D Karaboga - 2012 - books.google.com ... Cited by 916 Related articles All 3 versions [Download Book]