The Simpson's is a parody and so what appears on the show is protected, for the most part, by fair use. However,
The Simpson's also had the original genius to have appear on their shows the very people they wanted to lampoon - these people, in essence, become parodies of themselves - and
Fox Broadcasting avoids lawsuits.
Fox Broadcasting and all the other television networks, have large legal teams (and large legal budgets) to review episodes before they air, to prevent material from appearing that could result in a lawsuit. These legal teams are not always successful in preventing suits, however. Fair use has had to be determined at the court level several times in the past.
Family Guy and
South Park have both faced lawsuits over defamatory material and over copyright infringement from episodes aired. Novelists are not immune from lawsuits, either - the author of
The Wind Done Gone was sued over this
Gone With the Wind parody. Musical parodies of Roy Orbison's "Pretty Woman" by
2 Live Crew, and
Family Guy's "When You Wish Upon a Weinstein" parody of "When You Wish Upon a Star" have led to copyright infringement suits. Copyright infringement suits have even been brought against a dog toy manufacturer (by Louis Vuitton over the dog manufacturer's "Chewy Vuitton"s), and the owner of the copyright on
Barney, the purple dinosaur, brought a suit against the creators of a
Barney parody (and a parody of
Barney almost seems redundant
).
Suits have been brought against novelists frequently enough so that many if not most publishers now take out special insurance in the event of a copyright, libel or trademark suit brought against their authors.
Fair use is not always fair use, in other words, until a court determines it is fair, and the television show creator or musician or novelist who wishes to lampoon someone or something, or criticize someone or something, is always wise to review the material with an attorney first, to minimize the chances of a suit.