Having an A-Lister cameo in a movie can be the greatest gimmick weapon in a director's arsenal. If a cameo is used well in a comedy it can get one of the biggest laughs in the film, think of Chuck Norris' random and unexplained appearance at the end of Dodgeball as the judge who determines the fate of the competition.
Similarly when an actor with a history linked to the film makes a cameo it can provide an extra level of meta detail, such as Johnny Depp appearing as an undercover cop in 2012's 21 Jump Street, a franchise based on the TV series which made Depp a household name.
However, if done wrong a misplaced cameo can take an audience right out of a movie as they spend the rest of the film's runtime thinking "was that Ferris Bueller who just popped up in Manchester by the Sea?"
Sometimes having a big name actor appear in a quirky three minute scene actually ruins any world building the film had managed so far by taking the audience out of the scene and reminding them where they are: in a dark room watching a film.