We have to keep in mind that in Shakespeare's times theatre was not as it is today - while he performed with a troupe before an audience, less moralistic companies allowed the audience to... uhmm. Participate. Only towards the nineteenth century did we move to fully observational theatre as we know it today.
    If one looks closely, only the upper-class affairs were tightly regulated during the Elizabethan Era, the commoners were as dirty as ever. Sexual performances were not uncommon, and because of church law young boys had to play the roles of women. A good example of this is found in the beginning of Rosenkrantz and Guildentein are dead, where the protagonists run into a traveling troupe inviting them to partake in a 'play' featuring a small boy dressed as a woman.

So, in comparison, Shakespeare was clean as a whistle - and therefore allowed to perform for the queen.