Textbooks take a lot of time and effort to write, so why would a university support their faculty to do so?
Why wouldn't they? Writing textbooks is an important form of scholarship, with great influence on the field, and this is something universities should strongly encourage. The only reason I can think of not to support textbook writing is the profit issue, but this is not generally an important factor, since very few textbooks make a lot of money.
The fact that U.S. faculty are allowed to keep the royalties from textbooks they write is a historical contingency, and there's no reason why the system has to work that way. However, I think it's a good system in practice. Overall, the incentives to write good textbooks are too low, since both the financial rewards and the academic rewards are generally small compared with the time commitment. Removing the (small) profit motive would leave the incentives even lower, and I think the net effect would outweigh the tiny increase in university funding.
What about the grad students that edit and also work on the textbook? It seems as if they are working to fill the faculty member's pocket while being [partially] supported by the department/university and expected to do research.
If grad students are being enlisted as unpaid labor, then that's a real problem, but in my experience it's not common. If there's any prospect of nontrivial royalties, then it's unethical to ask students to work without compensation. Furthermore, the arrangement needs to be formal enough to include a copyright transfer (otherwise, the students will own the copyright to their contributions).