In my opinion...
I always start like that, as it helps keep the lawyers off my back. :-)
In 1933, Twentieth Century Fox lost a landmark lawsuit in America, when they released a movie which slandered a famous celebrity. As a result of that lawsuit, every movie made since that day (and every tv show) carries a written disclaimer printed on the film - usually in the end credits - saying (roughly): all characters are fictitious, and no reference in this photoplay to any person living or dead is intended or may be implied.
That is the legal protection the studio needs to prevent someone suing them for libel/slander: an express statement that everything in the film is fictional.
Thus, they can say what they like about who they like, because if it's clear that the film is a work of fiction it can't amount to defamation of anyone's character.
It is true that there are other defences in law to an action for defamation of character. Truth is certainly one such. But it is unlikely that a studio would claim both that its film is a work of fiction and that it is true! That would be silly.
Also, it is much easier to prove that a film is fiction, you just show that the usual statement/disclaimer, as above, is included in it. It might be much more difficult - and expensive - to prove that something said in the film is true.
The more ludicrous the statement, the less likely it is to even appear to be defamatory, due to being impossible. You could say a lot of really silly things which couldn't possibly really have happened, and you then wouldn't even offend the subject. Not only would it not be defamatory, it wouldn't even appear to be, as with the plot thread of someone co-operating with a government agency. Who'd ever believe someone would be likely to??? :-)
You quickly cross the line from libel to publicity. No one objects to free publicity!
You really can't do this sort of thing in a current affairs or documentary production, but in an entertainment context you can get away with a lot. For example, The X Files was not always complimentary about the FBI, but it was a fictional drama, not a news broadcast. You can take a real organisation and treat it fictionally, without getting into legal difficulties.
Generally, all you end up doing is giving the organisation some free publicity, in return for making (limited) use of its good name.