Interesting question.
I'm pretty sure that a character in a work of fiction can comment about a public figure without getting the writer into trouble because that comment is, by definition, fiction.
Also in general you have more leeway to comment about famous people because, being famous, they have less of an expectation of the kind of privacy that ordinary people have.
I am living an ordinary life and if somebody writes me into their book I may be able to stop them because it's an invasion of my right to privacy.
If I'm Beyonce, by becoming famous I've pretty much given up that right.
Again, though, it depends upon what you write.