Because they are fun, and fun is the whole point. Games are built to be engaging, and that engagement produces the good mood almost automatically.
There is more to it than that, though. Games give you clear goals, steady feedback and a visible sense of progress, which is a combination that tends to feel satisfying in a way that a lot of everyday tasks do not. Add a social element and the effect is stronger still.