Firstly, there's a Miztva of writing your own Sefer Torah and a Sofer can write on behalf of others who can't write themselves. But even if you hire a Sofer you must participate in the process in some way - the Talmud mentions that you should buy the klafim, for instance, and usually the "Baal Hasefer" writes a word or more in the Torah. But which word?
Three possibilities are mentioned: "Bereishit", the very first word, or "Israel", the very last or the whole passage of Devarim 33;4 - "Torah Tziva Lanu Moshe (...)". In a best case scenario the owner would write all three but almost no one knows how to write properly and to even write one of the three possibilities is already unrealistic, so the Sofrim found ways to go around this problem.
The "Keter Shem Tov" says that the Sofrim in his time would draw small dots outlining the words Bereishit and Israel, and the Baal Sefer would literary connect the dots. That's one solution.
Today, the Sofrim outline the letters and the owner just fills in. Halachically speaking, an outlined letter is Kosher thus the owner is not actually doing anything - the Sefer Torah is actually finished before he fills in.
But we haven't answered the original question: why is there the Minhag of letting others write a letter in the end of the Torah?
The "Mei Yehuda" offers a nice theory. Halacha says that if a person buys an unfit (Pasul) Sefer Torah and corrects it, he fulfills the Mitzva of writing a Torah. But there's an obscure opinion that says that even if the Torah belongs to someone else, the one who corrects it fulfills the Mitzva the same way. If so, it could be that people that write a letter in the end of the Sefer Torah do fulfill the Miztva according to this minority opinion and maybe that's how this Minhag started.
Be it as it may, this is an ancient Minhag Israel and in many cases is the only indication that the Sefer Torah was written by a proper Sofer - a Torah could look 100% kosher but be written by a gentile, for instance. This Minhag helps us with this issue and here is why:
Before the Sofrim came up with the outlining idea, the owners and guests would write the last letters themselves and, expectedly, the result was somewhat messy - you could tell that the letters were not uniform. But this mess was a good thing; if a Sefer Torah had perfect letters in the end, it would indicate that it wasn't unveiled in public, which is not a good sign. Only when it had the messy letters we would know that there was a public festivity and other people wrote the messy letters, which tells us that the Sefer Torah was most likely Kosher.
This is a great example of Chazal's saying: "Minhag Israel Torah".