According to an article by Megan Garber at The Atlantic, they did it for the drugs.

Starting in the 1300s, Europeans developed a taste for hallucinogenic drugs. Unfortunately, ingesting them often caused nausea and vomiting. Absorbing them through the skin came with fewer side effects and delivering them through the mucous membranes of the female genitals was ideal.

A physician quoted at The Guardian says the claim is medically sound:

Ointment would have been very effective as a delivery method… Mucous membranes are particularly good at transporting drugs – that’s why cocaine is snorted… Vaginal application would be pretty efficient, and the effects of the drugs would be noticeable quite rapidly.

According to legend, then, witches would coat the handle of a broom — a convenient household item — lift their skirts and get high.

The women who trafficked in hallucinogenic substances were often accused of being witches. Or, conversely, women accused of being witches were also accused of making magic ointments (from the fat of murdered children, no less). And witch experts in the 15th century claimed that they used these ointments not just to get high, but to get high; that is, that they literally flew using ointments.

Hence, witches on brooms.