I have been a co-author on two technical books and I can tell you that the answer is this: it's because writing books is hard!
I would have to come up with the materials, validate all references and then also do my own screenshots/code/graphics. You'd think that some people would do that for you, but writing is actually quite solitary work.
From there it's shipped to the editor who puts it through a peer-review process with 4-5 people, each with their own perspective. It get's shipped back to you with dozens and dozens of comments and questions. No matter how good you are, you are always going to have various comments to address. The editor wants to see you address every single one and some of the comments will be very good and can spark new ideas in you and add sections to the books. Other comments will require you to re-do some of your screenshots/code/graphics.
After you ship that back, the better book publishers will put it through another peer-review process and you have to go through the same cycle above until you get down to a reasonable level of comments.
And all of the above is just for ONE chapter!
Think of a book with 20+ chapters and hundreds of pages. The writing is (almost) the "easy" part - the review process will cause you to tear your hair out. If you're a true professional, working in the field you're writing about, you really just don't have the time needed to write a book completely on your own. The person in the other answer who said it takes 6 months to write a book is clearly wrong - if you go at it yourself, you're looking at 18 months, more like 2 years to be realistic. So it only makes sense to involve other people in the process to keep your sanity in check.