This is a good question. I would say that there are three main reasons for this.
First, we need to keep in mind that Shakespeare is writing within a certain historical context. In this context, women could be powerful. Think of Elizabeth. So, the idea of a powerful woman is not something unthinkable.
Second, Shakespeare is drawing from the Greek and Roman comedies. In these comedies, women often play a more dominant role. All you need to do is think of some of Aristophanes' plays or Plautus'.
Third, comedy, from a theoretical point of view, is based on an inversion of the world. So, within a society in which men usually held power, a powerful woman who even overcomes men is funny. In other words, the dynamic of comedy is similar to the dynamic of carnival. This is why slaves in Roman and Greek comedies often outwitted their masters.