Did last week's unusual, significant judgment at Glasgow High Court give a licence to commit murder and hate crime?

Or did Ryan Esquierdo's case reveal a frequent underlying reason for young men's "motiveless violence", which needs urgent attention to prevent more tragedies?

The 19-year-old violently killed Stuart Walker, a popular gay barman, near Cumnock, then set his body alight. The Crown accepted his plea to culpable homicide through diminished responsibility. This followed psychologists' evidence that he was in the throes of a flashback and post-traumatic stress disorder (PTSD) after being sexually abused as a child.

Meeting by chance late one night, they got talking about the teenager's confused sexuality. Mr Walker was sympathetic and helpful, but a consensual sex act caused Esquierdo to panic: flashbacks of abuse during the act triggered "uncontrollable rage" and explosive violence.

Derek Ogg QC, defending, said the killing was "not a gay hate crime" but "far more complex", adding that Esquierdo (a first offender) felt "utter bafflement and horror that he could inflict such violence".

Just an excuse? Understandably Mr Walker's family, friends and neighbours in Cumnock were distraught, describing it as a "disgrace" that someone convicted of such a brutal killing was "allowed to get away with murder".

There was alarm too among gay campaigners against hate crime: Stonewall's research found one in five lesbian gay and transgender people in Britain suffered homophobic hate incidents in the last three years. Seven out of 10 did not feel they could report these.

The most dramatic increase was in Scotland. Here, recorded homophobic abuse has risen five-fold in five years, police statistics show.

My own research at Edinburgh University – and the experience of organisations working with traumatised offenders – suggests there are many abused young men convicted of serious violence against men they knew or thought to be gay, or men who had just looked at them "the wrong way". (It's very important to say clearly that most sexual abuse survivors don't offend; however, many repeat or violent offenders have been sexually abused.)

Often they are wasting their lives and our taxes serving long jail sentences. Abused by men, they bottle up their anger for years, deeply ashamed to tell anyone because it's not "masculine" to be victimised; worried and confused they might be gay, which isn't macho; suffering untreated PTSD, hypervigilant against any apparent threat or "funny look". They tend to blame gay men for their own abuse by paedophiles; sometimes exploding in dissociated, trance states, unable even to understand their own actions.

Those convicted offenders I interviewed had all been multiple sexual abuse victims. Most felt hostility or mistrust to gay men.

Paddy, who used to attack sex offenders in jail whenever he could, explained: "I had a habit of lashing out when somebody was getting too close - the only thing in your head is protecting myself. That's how you see a lot of innocent people getting hurt." Mike explained: "You swear to yourself that if anything like that is going to happen to you again, you'd kill because you'll not let it."

Danny has committed serious violent offences, including fire-raising: "It's more to like seeing something destroyed, because part of you has been destroyed."

What is the answer? It's not about excusing violent assaults, though more compassionate lengths of sentence in identified cases of PTSD and flashbacks are merited. Spotting the problem much earlier in abused boys, and helping them reveal abuse sooner, are far more important, and will also reduce wider homophobia which contributes to anti-gay crime.

Work is urgently needed with boys in schools and youth settings to reduce the conviction that being sexually abused is shameful to masculinity, that homosexuality or uncertainty about your sexuality is shameful, or that gay people are to blame for paedophiles' behaviour.

The Violence Reduction Unit in Scotland needs to take this issue seriously on board as part of its work, and acknowledge its role in violence among young men.

After sentence there must be more, and longer-term, support for skilled trauma work with prisoners, which will also reduce their risk to others. Voluntary sector agencies such as Scottish Association for Mental Health, Stop it Now (Scotland) and Open Secret have been working hard on abuse trauma issues, including staff training. But they need greater resources, more consistent funding, and Government commitment to the work they do.

l All names have been changed.

Dr Sarah Nelson is a researcher specialising in child abuse, based at Edinburgh University.