Copyrights exist to keep other companies from shamelessly using the characters of another company for pure profit purposes without permission. There is a reason why you won't see Batman or Superman show up in Marvel Comics or Spider-Man or Captain America show up in DC Comics, outside of a mutually agreed company crossover. It is essentially to protect the intellectual property of a company but there are ways around copyrights, providing the people do not get too ambitious for their own good.
There is a fine line between copyright and a parody of a character. It is all about how the character is presented. A brief, blink and you miss it cameo, which amuses the people watching and perhaps might not have been caught by the vast majority of the audience watching is considered a parody. Technically speaking, they aren't using the character, but they are paying homage to them.
It might resemble the character but technically speaking it is not the character. The parody has no overreaching impact on the plot. It is just something to amuse the fans and to have a cute, "blink and you miss it moment." Unless someone is rather going to be vicious about their intellectual property, very few people are going to sue on the parody.
Of course, it has to be done very carefully. A parody cannot overstay its welcome for more than about a minute, as it can dangerously be close to breaching some kind of intellectual property agreement. So get them in and get them out, and don't spend too much time focusing on them. That aspect is a key to a good parody in entertainment.
A rather enhanced version of a parody is where a character is drastically changed but you still get the underlying version of what they are supposed to be. They come across at the very best as a distant cousin of the character that they are portraying but they are just careful enough to avoid being completely classified as a shameless rip off that violates copyright. The term for these is an expy, a term mostly notoriously coined in the time vampire that is the TV Tropes website. The most shameless of these is a Captain Ersatz, another term coined on TVTropes. Where it doesn't appear that they are trying as hard.
Obviously these are more towards the potentially shamefully parodies, edging towards blatant copying. Of course, if it becomes a successful copy that gets some interest and there is some money to be made, that is when the copyright infringement sharks start smelling blood.
Copyright issues involving characters also occur with the creator or heir to the creator and the official company that work involving characters have been published. There are reasons why most companies require creators to sign the rights to their characters over to them. There have been some headaches over the years, most famously with Superman and the rights, but also there have been many questions, back in the day.
When the rights are tied to a company, then things are more crystal clear. When the rights are loaned to the company, by a creator, that is when the murkiness happens.
In the end, a parody is all in good fun. An homage to a character might consider to be all in good fun as well, until there is money to be made by the infringed party of you and they start raising questions. Then the big problems with copyrights occur when creators or the heirs try to angle for more from the company. Hence why companies own the rights to characters more and more and not creators.