Many movies and TV shows seem to do it without making the people creating the stereotype the protagonist or the hero of the film. I think that’s the difference. Make the Muslims, immigrants, whatever the protagonists and then you can showcase the stereotypes and the racists, sexists, bigots, whatever in a way that doesn’t celebrate them as centered.
Or just create comedy that doesn’t rely on sexism or racism to be funny. I think that’s why Vince Vaughn isn’t getting the movie deals anymore, and I don’t think it’s only because producers are scared for their jobs, it’s also because the market for low brow humor is less than it was in the aughts.