"Franchise building" isn't a satisfactory answer, either.Some will say that post-credits sequences occur so as to tie various movies together.
I like the post-credit sequence of Dawn of the Dead (2004), for example, which establishes that survival is not a guarantee.
Also The X-Files: I Want to Believe (2008) features a very brief post-credits scene that functions ably as emotional catharsis. After the wintry, icy nature of the film's setting, the film's farewell to Mulder and Scully -- in a warm, tropical setting -- feels like punctuation and tension release, not desperate add-on.
But broadly-speaking, the desire to include a post-credits sequence comes from the desire to make money; to get the viewer thinking about spending more money, on a new work of art.
There you are, watching the end credits, reflecting on the film. You should be thinking: Did it work for you? Did it succeed? What did you like? What didn’t you like? What are the film's artistic merits?
A good, well-made movie is the best hype of all, after all.