No one can agree on its exact origin or how the meaning came about, but the modern use as a derogatory slur against women didn't begin until the late nineteenth century and rose to infamy through many different works of literature. Most often, degrading a powerful woman and dismissing her worth or intelligence.
However, the word was regularly used to mean a "stupid person" throughout the Middle Ages.