If you were tried for witchcraft in early modern Scotland, one of the surest ways to be convicted was to confess. Of course, you didn’t need to confess to be convicted, and confession wasn’t always voluntary. This problem led to a practice called “waking the witch”: a form of torture that involved depriving the accused of sleep for days on end, until they were so exhausted they would hallucinate and babble incoherently. These “ravings” would often later be used as evidence of guilt.

It sounds barbaric and antiquated: accusing a woman of being strange and unnatural, driving her mad with constant prodding, depriving her of sleep. But it also sounds chillingly familiar. I was reminded of a teenage girl I had recently met who, after an incident involving a boy at her school had gone viral on social media, began being bombarded with abuse by her peers. They called her a slut and a slag on multiple internet platforms. They shared embarrassing photographs of her, while forever escalating rumours started to spread. But unlike my own adolescence, when some escape from school could always be found at home, this young woman’s life had become a prison of endless abuse. The alerts and notifications pinged directly to her phone, vibrating through the night, causing her to become more and more panicked as sleep deprivation set in. Having initially rejected the labels others were assigning to her, she started to fear that they were right. It’s hard to hold on to who you are when dozens of people are telling you that you’re worthless. Does this sound like an exaggeration? For thousands of teenage girls across the UK, it isn’t.

One woman was accused of being able to transfer labour pains on to a pregnant woman’s husband

When I first started researching the witch trials that swept through Scotland between the 16th and 18th centuries, I was shocked by the cruelty and misogyny of many of the practices that flourished during that time. Duplicitous professional “witch prickers” roamed the country, using trick needles to test suspects’ bodies for “witches’ marks”, which they claimed would prove their guilt. Sexism was rife, with the majority of those tried for witchcraft being women. Deep anxieties about gender and sexuality crept into the trials; one woman was accused of being able to transfer labour pains on to a pregnant woman’s husband, while others were accused of fornicating with the devil. Ad hoc local courts flourished, where prominent men essentially became both judge and jury; execution rates soared to around 90%. Between the passage of the Witchcraft Act in 1593 and its repeal in 1736, Scotland saw around 5,000 witchcraft prosecutions – three times higher than England, despite having just a quarter of the population. It is estimated that more than 1,500 people were executed in Scotland alone.

As I dug deeper, uncovering the details of individual trials, I was struck by the similarities between the women then and the virtual witch hunts young women are going through today. “Dunking”, where a woman was submerged in water as either punishment for being a “scold” or to ascertain her guilt in a case of witchcraft, reminded me of the girls I meet now who find themselves trapped between two bad outcomes. Like being put under enormous pressure to share nude photographs, then rejected for being frigid if they refuse or castigated as sluts when they relent.

Many trials – like the memorable case of the woman accused of cursing a man by giving him a permanent erection – suggested that women’s feminine wiles gave them unfair control over men, whose own sexual behaviour was framed as involuntary. I read the stories on train journeys, on my way to school visits where I would meet girls who had been punished for school dress-code violations, who were told that the sight of their shoulders, knees or bra straps was unfair to male teachers or risked distracting the boys. I heard from girls who had been sexually harassed or even assaulted by boys at school, groped and upskirted as they climbed stairs between lessons. In some cases, their predominantly male supervisors’ only answer was “boys will be boys”, with any blame placed on their own dress or behaviour. (“He probably just likes you: did you do something to lead him on?”) Girls whose images were shared online without their consent were frequently given punishments equal to or greater than those who had done the sharing. Many were forced out of school altogether, some because of sexual bullying and others after enduring draconian punishments for the crime of being a victim.

Maggie Wall Memorial, Dunning, Perthshire, remembering a 17th-century witch hunt victim. Photograph: Geoffrey Davies/Alamy

The parallels kept mounting. Women accused of being somehow inherently dangerous and powerful. Their bodies blamed for causing innocent men to behave in ways they could not control. Punished and shamed for their sexuality, their guilt determined and punishment executed by groups of powerful men.

And even today, young women who dare to call themselves feminists risk attracting the same label: witch.

As I spoke out about what I had seen and heard on my school visits, people often responded by bemoaning the perils of social media and the problems they had created for young women. As if these were new and startling issues that had arisen purely because of technology.

One day, I stumbled across the story of a young woman named Maggie, who lived in a tiny fishing village in Fife in the mid-17th century. Her treatment by her local community 400 years ago seemed near-identical to the experiences of the girls I work with today. As I read about unmarried, pregnant Maggie who was confined to the “cutty-stool”, a three-legged chair raised above the church congregation on Sunday, so she could be humiliated by the minister in front of her neighbours, I knew I had to tell these stories side by side. Derided as a “harlot” and a “limmer” despite being the victim of abuse, Maggie was accused of witchcraft after the man who had harassed, impregnated and then abandoned her was lost in a fishing accident.

I wanted to give a voice to the girls whose stories still aren’t being heard, whose accusations are so often disbelieved and whose bodies are blamed for their own injuries. I wanted to remember the women whose voices have been lost to history, never allowed to speak out or record their own version of events. And most of all, I wanted the opportunity to say: Look! This isn’t a new story. It’s not a modern invention or a problem created by the internet. It won’t go away on its own, unless we do something to change it. These stories span four centuries. These stories are the same.

• The Burning by Laura Bates is out now (£6.99, Simon & Schuster). To order a copy, go to guardianbookshop.com. Free UK p&p on online orders over £15.