How do these affect your academic reputation? Or are they primarily making them money? I don't quite understand, because many of these books are really quite basic and expository in nature.
This question seems to be based on a false premise, namely that the two primary reasons for writing a book are developing a scholarly reputation or making money.
One common reason to write an introductory text is dissatisfaction with the available options. If you write your own textbook, it will be a perfect fit for how you feel the course should be taught, and you can address any deficiencies you see in competing books. If nobody else seems likely to write the book you have in mind, then writing it yourself may be preferable to repeatedly using books you dislike.
More generally, many books are written as a service to the community. Depending on how cynical you are, this could be viewed as noble (taking on a poorly paid and not particularly well respected job for the benefit of the world's students) or self-important (believing that you have unique and valuable insights on topics that hundreds of teachers with equal or greater experience have thoroughly addressed).