What follows is offensive. The facts are unattractive and there is no hero in this story. On 30 April, two days after teacher Ann Maguire was stabbed to death by a pupil in Leeds, Jake Newsome, a 21-year-old man who had himself attended a secondary school on the other side of the city, posted on his Facebook page: "Personally im glad that teacher got stabbed up, feel sorry for the kid… he shoulda pissed on her too".

"Thats not very nice" reads the first of 37 comments on his post. Others soon chipped in, addressing him by his nickname: "Greeny come on! You're better than that" wrote one. "Greeny seriously that's harsh" wrote another. "Greeny, not sure you should be saying this stuff on facebook man – people get in trouble for this kind of stuff".

A few days later, after his post had been shared more than 2,000 times, West Yorkshire police arrested and charged Newsome under the 2003 Communications Act with having sent "by means of a public electronic communications network a message or other matter that is grossly offensive or of an indecent, obscene or menacing nature". Last week Newsome was jailed for six weeks, after pleading guilty, with the judge quoting his post back to him and saying: "I can think of little that could be more upsetting or offensive."

Newsome was the second person jailed for social media offences related to Maguire's death. Last month Robert Riley, a 42-year-old former bus driver from Port Talbot in Wales, was sent to prison for eight weeks after his tweets about Maguire, in which he said he would have killed her colleagues as well, led to complaints and the unearthing of other offensive material on his Twitter feed, including racist insults. A teenager from Cardiff was also arrested and bailed.

Such events now follow a familiar pattern, with the torrent of online reaction to the highest-profile and most shocking crimes reliably including offensive elements. In October 2012 Matthew Woods, 19, was jailed for three months for posting sexually explicit comments about the abducted child April Jones, after being arrested for his own safety when an angry crowd gathered outside his house. Also in 2012 Azhar Ahmed was prosecuted for a post made two days after six British soldiers were killed in Afghanistan, in which he wrote that "all soldiers should die and go to hell", and biology student Liam Stacey was jailed for two months for racist tweets sent after footballer Fabrice Muamba suffered a heart attack – a sentence criticised by European human rights commissioner Thomas Hammarberg.

Last year more than 10 arrests were made in the aftermath of the murder in south-east London of soldier Lee Rigby, and one man, Benjamin Flatters, was jailed for posting anti-Muslim material.

Writer and campaigner Caroline Criado-Perez faced a campaign of harassment and violent threats on Twitter, for which two people were jailed. Photograph: Sarah Lee for the Guardian

That the levels of insult and quantity of hate speech found on social media offends many people is well known. There has been widespread outrage about the abuse by online trolls of a handful of public figures, the swimmer Rebecca Adlington and diver Tom Daley among them. In January Isabella Sorley was jailed for 12 weeks, and John Nimmo for eight, for their part in a Twitter campaign of harassment against the feminist campaigner Caroline Criado-Perez, who led efforts to get a female historical figure on a British banknote. Criado-Perez described the experience of receiving repeated violent threats as "terrifying".

The cases of Newsome and Riley are different. They did not target or menace individuals, and lawyers and human rights campaigners have this week raised concerns about their being jailed for causing offence.

Thomas Hughes, executive director of free speech organisation Article 19, said the charity is "extremely concerned by the number of arrests and prosecutions for comments made online in the UK. Nobody should go to prison simply for causing offence. This is not only our view but a violation of international legal standards that protect speech that shocks, offends or disturbs." Jo Glanville, director of the writers' network English Pen, said of Riley: "He hasn't incited violence, there's nothing around public order, so it's purely for being tasteless. I think we're seeing something new here. It's a chill on freedom of expression. Causing some distress to members of the public shouldn't be enough to get you a custodial sentence."

Lawyer and legal blogger Lyndon Harris described Newsome's case as "a knee jerk reaction by the CPS" and told the Guardian the law is "failing miserably. At what point does unpleasant become criminal? You're just locking people up for saying nasty things. If someone said that to you in the pub and you went to the police, they'd tell you to go away."

Keir Starmer, the UK's former director of public prosecutions, believes that 'too many prosecutions for these kinds of offences can have the effect of chilling free speech'. Photograph: WPA/Getty

Former director of public prosecutions Keir Starmer, who issued new guidelines for social media cases exactly one year ago that stressed the high threshold for prosecutions, said "there needs to be a debate, the debate needs to take place in parliament and it needs to take place sooner rather than later".

He believes his guidelines have done "a good job in difficult circumstances", but politicians now need to step in.

"There always used to be a protected space, so you could say things in private you could not say in public. With social media there is no protected space, and that's what there needs to be a debate about. The notions around place and reaction just don't work with social media. You could have a situation where two people in their living room make remarks to each other for which they would never be arrested, but if they make these remarks by email, they could be, as the legislation covers any public electronic communication system."

The law most often used in such cases, he points out, is an updated version of one from the 1930s that was designed to protect people working in telephone exchanges from obscene phone calls: "Eighty years on, it just doesn't work. This hasn't been seen as a priority in a time of austerity, but change is overdue. I've always thought that too many prosecutions for these kinds of offences can have the effect of chilling free speech."

But if free speech is threatened, where are its defenders? When asked to comment on last week's sentence, Index on Censorship chief executive Jodie Ginsberg said the CPS had ignored its own guidelines, which was "highly damaging for free expression in this country". But beyond a tight circle of specialists, reaction to the jailing of two men for posts made after Maguire's murder has been muted, which is perhaps more surprising in light of Facebook's decision to reject complaints about Newsome's post and leave it online, on grounds that it doesn't violate the company's community standards. In other words, a post regarded by the British state as so far beyond the pale that its author has gone to prison is still allowed on Facebook. Facebook's director of public policy in Europe, Richard Allan, who is also a Lib Dem member of the House of Lords, declined to comment, though a spokesperson stressed that Facebook is making efforts to educate users about the possible consequences of social media use.

Until the trial of Peter Nunn, accused in relation to tweets sent to the Labour MP Stella Creasy, the most celebrated social media case in this country is likely to remain that of accountant Paul Chambers. In 2012 Chambers was cleared on appeal on the grounds that a tweet in which he said he would blow up an airport, after being stranded en route to a date, was a joke and not a menace.

Paul Chambers (middle) found support from comedians Al Murray (left), Stephen Fry and others after he was convicted over a joke he made on Twitter. He was later cleared on appeal. Photograph: Rex

Chambers' supporters included comedians Al Murray, Stephen Fry and Graham Linehan, and a benefit gig was held to fund his expenses. But the notion of free speech as a right to be defended online has been overshadowed by cases of misogynist threats and abuse.

"Why hasn't there been more of an outcry about recent cases?" says David Allen Green of Preiskel & Co, who was Chambers' solicitor. "The novelty of Twitter has worn off. Would you really want to argue in favour of someone making unpleasant comments about someone who has just died? These cases are less attractive, though some would say that's when you need free-expression protections even more."

Glanville agrees. "It's often cases that don't seem to have particular merit in terms of artistic value, or promoting the public good, that are the landmarks. I'm thinking of the obscenity trials in the 1970s – the Oz trial, the Linda Lovelace memoirs. Nobody would say these works had literary merit, but those cases were very important for the greater protection of freedom of speech and our culture as a whole. It's very important these cases are challenged. I do think we are seeing a chill on freedom of expression that ranges right across from the press to the foul-mouthed blogger."

None of those who have served prison sentences for offences committed on social media wanted to talk to the Guardian. They are nobody's heroes and know as much, though Jake Newsome's defiant Facebook post a week after he was told that he could face jail – "I will always say what the fuck I want" – does show in its ragged way that he believed constraints on speech were at issue.

Guilty pleas have meant there have been almost no attempts to defend such behaviour in court, and very little legal argument about just what "grossly offensive" means. Instead, lawyers have spoken at sentencing hearings in mitigation, and focused on defendants' immaturity, weak grasp of social media, or the influence of alcohol.

"There is a fear of social media and of how dangerous it might or might not be," says Glanville. "It is something I think the police and courts haven't yet worked out how to deal with in a common-sense way, and in their attempt to deal with what is still a very new area, I think they're over-reacting."

Whether those convicted of these offences or the other people most closely affected by them agree with her, it's hard to say.