In this question it is mentioned that you can't use a character from another novel in your own novel.
But if characters in my book talk about fictional characters in other books, that seems to be ok. So for instance, if I write a book and one of my characters mentioned Harry Potter that is ok, at least according to answers to this question
But how far can this be taken in terms of meta references? In an answer to the above it is stated:
Your characters can talk about Luke, swing swords around like Luke, and watch Luke. They just can't BE Luke.
But can my characters in the show pretend to be Luke? Or, could I write a novel in which some of the characters create their own story involving Luke which, in the novel itself, violates copyright, and, again in the story, might involve some of the characters in the story getting in trouble legally for what they have done?
Assume that I'm not saying anything disparaging or defamatory. I'm also not planning on pages and pages of quoting verbatim what the people in the story are writing, trying to create a loophole. But I may need to frequently reference things from the original work and quote some things from time to time to tell the story.
For instance (and this is just something I made up on the fly for the purpose of illustration of the type of things I need to do and is not my actually story idea.) suppose I had a passage that went something like this:
The next day the gang found out they were in some legal trouble when they were served a subpoena. Dennis brought in in, frowning.
"Apparently," he said, "creating a shell of the Millennium Falcon around the pub was some kind of intellectual property theft."
Dee had dressed up like Princess Leia in a skimpy gold bikini just like in the movie except sluttier, and the suit complained that this was defaming the brand. Dennis also had the idea of giving hobos fake printed "imperial credits" to use in the bar to encourage them to drink, and in characteristic fashion forgot to find some way to actually get real money from them. The whole idea had been a smashing success, with many patrons even dressing as Star Wars characters. Everything had gone well until a little person dressed as Yoda had gotten into a light sabre fight was another patron dressed as Obi-Wan Kenobi (the older version from A New Hope, not the younger one) over an insult about his size. Despite all this, the gang in their characteristic fashion decided to ignore the summons for disturbing the peace and the subpoena for intellectual property theft and gave it to Charlie, who promptly used it as bedding for his pet rat. Mac, in the mean time, took the confiscated light saber and began sparring with an unwilling Dee, talking about how he would slice George Lucas' head off if he showed up before being reminded that Star Wars was now owned by Disney.
So in this example I am mentioning a lot of aspects of Star Wars. Later in the story, the characters might re-enact scenes from the story with alterations, although the story would just highlight it from the standpoint of the alterations and what terrible acting it was and how something they all managed to avoid going to jail at the end. In general, it seems like characters doing something illegal in my book doesn't automatically make what I am doing illegal. Would a story like this require permission?
Now there's a second part. The characters doing this infringement are actually characters from a TV show which I obviously didn't create. So I couldn't actually write this story for that reason. But what if I am writing a story about a person who is doing this sort of thing and they are asking their law professor if it is legal, and they give an example to the professor, verbatim the way I wrote it. Now is it legal in my story?
Where are the lines of when I can and can't use references to characters in other stories when there are meta levels of indirection. If this is too much is there some way I can dial it back, some line to not cross so it will work? It's not my intention to actually steal anybody else's work, but to reference it in the context of a larger story which examines the implications of such an infringement in the story itself, and using a specific work is important due to certain constraints of what the story is trying to say.
Edit: If it makes and difference, this would be a short story which would in a larger book in which each chapter had one theme, almost like mini-episodes of the twilight zone where each chapter is unrelated to all the others. So there is some concern if one chapter has issues does it "contaminate" the whole book, or conversely does the opposite happen?
Another example: if the main character is involved in some sort of dream where they exist in the setting of another work. I have seen this on TV shows, for instance on Big Bang Theory, Sheldon has a dream from time to time where he meets Bob Newhart dressed like Obi-Wan and carrying a light saber and who dispenses personal wisdom to him. But did they need permission for this?