Two creative teams, two comic strips, two different uses for cameos. Having one comic strip character show up in another is something that's becoming more common -- especially in certain strips. But it's why a character appears that makes or breaks the sequence.
In this 1/12/17 sequence from Baldo, by Hector Cantu and Carlos Castellanos, the cameo reinforces the gag.
The third-panel punch line would be a little flat without Goofy appearing in the second. And without the punch line in the third panel, Goofy's appearance doesn't make much sense. Both are needed to land the joke.
The 5/3/17 sequence of Barney & Clyde takes a different approach.
Here the cameo is used for some meta-humor. it's something the creative team of Gene Weingarten, Dan Weingarten, and David Clark excel in.
Rex Morgan, M.D. is indeed a respected physician. The strip often tackles important medical issues in a fairly accurate fashion. And, in those papers that run both comics, Rex Morgan would be local to Barney & Clyde (most likely on the same page). The humor rests all on references to the world of newspaper comics.