That's because the plays are public domain.
So any show can reference and quote them without getting sued for it. http://shakespeare.mit.edu/
Pic related: it's also a trope that exists in anime for children.
(Japanese parody laws are stricter so you can get sued/censored by directly referencing another show who isn't in public domain; in fact, in Osomatsu-san, they are removing the first episode from the DVD release because it made fun of Attack on Titan (and other anime shows).)
Making fun and directly referencing public domain work like old-ass theatrical plays avoids all these types of nuisances and legal troubles. Shakespeare's work happens to be chosen all the time because it's so popular and widespread any kid can recognize it.