Let's take three well know examples. Lawvere (set theory), Menger (calculus), MacLane (set theory,categories). All wrote textbooks.
All of them indicated that they did it primarily to (a) make more accessible a particular way of approaching some basic material which they would like to see more of, (b) to determine, while writing, what is (in fact) the best current way to approach the basic material if you want to teach it to somebody, and (c) to attempt improving or revising basic notation used in mathematics more to their liking.
I suggest that (c) followed by (a) followed by (b) is the ranking of how important these reasons usually are for motivation.
One may also want to provide a book reintroducing all the basic material in the most general and systematic way known at the time of writing, as opposed to the usual or original way the concepts were discovered or taught. Since the state of mathematical knowledge evolves over time, authors end up periodically writing general basic monographs. This is a special case of motivation (b).
I assume we are discussing books reintroducing all the usual basic material in perhaps a new way (or a way more concise or clear or abstract).
There are also quasi-popular books (not the same thing as new general textbooks) meant to attract more people to mathematics (Courant, Penrose), which find a good way to introduce basic or intermediate material creatively to a wider (but still technical) audience; this another motivation (d), and usually goes hand in hand with motivations (a) and (c), but I assume you are not asking about quasi-popular books.
In the end, it's the basic books by which an author is known to most individuals, so they improve one's reputation, in fact. This is to say that basic monograph writing is not merely done out of a sense of service to the community, although a desire to do a service is certainly a large part of all motivations (a)-(d) above. In a nutshell, it comes down to the author wanting more people interested in their field and doing work in the field more elegantly.
UPDATE: A clarification of (c).
Consider https://dx.doi.org/10.1017%2FS0305004100021162: not all notations are equally useful even if they are equally valid. They are different languages, and each makes it more or less difficult to write useless or uninteresting statements and more or less easy or automatic to write meaningful ones. This despite the fact that one could ultimately express what one means in any of these languages with sufficient effort (if they are all coherent ones).
Dirac's thesis is that in good or better notations it's difficult to make certain serious errors---and significant ubiquitous statements are easy to process and construct without much effort. (And which errors these are varies together with the subject matter.) So (c) is closely tied with (a), (b), and (d) and the appropriate notations vary together with the subject matter that is the meaning. Using good notations one learns more of what one doesn't already know because one learns more easily.
Consider how much reasoning is actually built into a given notation. (Mathematics itself is a constructed language with reasoning built into it.)
Yes, we must agree with Popper, it's not useful to argue about words, names or symbols, if their meaning is recorded or communicated, known. But different notations and conventions are quintessentially different compression schemes. What is easy to communicate or to record by means of one is not so easy to communicate or to record by means of another.
We recognize that language choice is meaningful only if we consider different languages as dynamical systems, each a more or less appropriate means of doing work that isn't already done, of communicating what isn't already communicated, of recording what isn't already recorded, not as entities that we find in work already done, in records or communications already made.
Each communication or record is an output of a language. Which language we use isn't a meaningful choice if we have the output present. There where we've yet to make the output (or are in process of constructing it) the language we use as means to getting output (and so the language we don't use) is a meaningful choice.
We get the same end with more or less effort by different means. So we get more or less work done or those we try to communicate a subject matter to learn more or less of what we desire to communicate. They have limited resources for learning or working and what means we use to communicate contributes to determining how easily they learn. We also have limited resources for doing work.
Making different outputs is easier by means of different languages. It's easier to learn a subject matter or to do future work in a subject matter by means of one language and not another. So in this case the choice of language is meaningful. Once the work is done or the subject matter is learned the choice of language in which it is expressed isn't meaningful.
Yes, which symbols are used to record or communicate a subject matter doesn't really matter once the content is recorded or communicated, constructed, ready. Only the content (meaning) of a statement ultimately determines its truth. Not its presentation. Which notation is used however does matter while constructing statements that communicate or record.
Some symbol choices and symbol combination conventions make some subject matters easier to comprehend or work with, record or communicate. Different construction rules make different statements difficult to construct and also to record or to communicate.
What is less easily done is less frequently done. So they appear less frequently.
A set of notational rules are good or better relative a subject matter if and only if statements they make difficult to construct are typically not true or trivial ones considering this subject matter.