Defence barrister Tim Marsh has a philosophical bent. A plea hearing is not a search for truth, he told the Victorian supreme court, but it is a search for an explanation. It was his task to explain why Codey Herrmann, aged 20, with no prior convictions and no history of violence, would viciously bash a young woman with a metal pipe, rape and murder her, and set her body on fire.

“I think it’s important for me to concede at the start that I will ultimately fall short in this task,” Marsh conceded to Justice Elizabeth Hollingworth at the hearing’s opening last Tuesday. “There is not an explanation I can give you that is going to get us from that start to that finish.”

Herrmann, now 21, pleaded guilty to the rape and murder of Aiia Maasarwe, a 21-year-old Palestinian citizen of Israel, in the early hours of 16 January. Maasarwe was studying English at La Trobe university, and in the hours before her death was living her life: attending a comedy show with friends before travelling home by tram.

There is not an explanation I can give you Defence barrister Tim Marsh

As far as we know, Maasarwe said only four words to Herrmann, in Arabic. “You piece of shit,” she screamed, as he came up behind her just after she got off the tram at Bundoora, a suburb in Melbourne’s north. It was a few minutes after midnight. Herrmann bashed her over the head four times with a metal pipe, before dragging her behind nearby hedges, striking her again perhaps nine times and raping her. She was unconscious for most of the attack, and probably dead when he set her body on fire. Herrmann has admitted that he intended to kill her.

In a legal sense, the purpose of a plea hearing is for the prosecutor and the defence to argue factors relevant to the sentence that should be imposed, including mitigating factors that made the crime less serious than others, and aggravating factors that made it worse. There was no dispute that Herrmann’s crime was exceptionally horrific and he will spend decades in prison.

The three days of hearings were about whether someone who could commit such an unprovoked crime should spend the rest of his life in jail, with the possibility of parole at a distant time, or be handed a defined sentence, perhaps 30 years or so.

Hollingworth acknowledged that hers was an “invidious task” to grade crimes as more or less serious, because it could seem insensitive to the family and the community, “but that is unfortunately what the law requires us to do”, she said.

Behind the legal arguments was the deeper story, the one that defied explanation. Herrmann, a slight man wearing a tracksuit top, sat at the back of the court. Through days of intense argument about who he was, what Marsh called his “extraordinary dislocation and disadvantage”, his humiliations, his substance abuse, his mental state, it was sometimes hard to remember he was there. His eyes were mostly downcast or staring into the distance. Occasionally he stroked his chin, or bit his lip. He seemed to be in his own world.

Codey Herrmann is brought to the supreme court. Photograph: James Ross/AAP

Maasarwe’s family was not present in court – they live overseas – but their pain was there. Her death became a symbol of women’s rage at being unable to go out at night without fear of male violence, but the picture that emerged of her was of an individual, a young, vibrant daughter, sister and friend who loved travel and study, spoke four languages, a woman who lost her life in a few minutes of inexplicable horror.

The plain-speaking prosecutor, Patrick Bourke, paused for several seconds, his bottom lip quivering, as he read out the family’s victim statements. Maasarwe’s mother, Kittam, still watches videos and reads her daughter’s text messages, just to see her and hear her voice. “‘I am a mother whom her heart has been squeezed in pain, day after day.”

Her father, Saeed, and sister, Noor, planned to visit Aiia in Australia. “A lot of time I find myself lost, lost in the crowds, or sometimes stuck, stuck in the past. Now I live with fear,” Noor wrote.

After Maasarwe hopped off the tram to walk the rest of the way home, she rang another sister, Ruba, in Israel. She often did that when she was alone at night, just to feel safer. The call was answered, and Aiia said to Ruba, “I didn’t expect you to pick up”.

Seconds later, Hermann hit her from behind with the metal pipe, before dragging her away from sight into a garden bed behind low hedges. Ruba heard the phone drop and her sister screaming.

The order of what happened next is not clear, but the prosecution says Herrmann strangled Maasarwe, bashed her a further nine times, and raped her. She died of extensive head injuries. In a futile attempt to cover up his crime, he poured the flammable solvent WD-40 over her, and set her alight.

For several hours before the attack, Herrmann had wandered around the nearby Polaris shopping centre, his image caught on CCTV. He spoke to a man and smoked a cigarette. He has given no explanation about what he was doing or thinking. He claims he doesn’t know how he found the metal pipe or the WD-40 – they are not visible in CCTV footage. He has said he didn’t plan the murder. Afterwards, he fled the scene, climbing over a fence into a nature reserve, leaving a trail of his DNA on his cap, the pipe, the can of fluid and on Maasarwe’s body.

‘I’ve seen fathers portrayed in movies’

There’s the crime itself and then there’s what led up to it. The forensic psychiatrist Dr Andrew Carroll interviewed Herrmann in custody and had access to more than 2,000 pages of material from the Victorian Aboriginal Childcare Association, which has had contact with Herrmann since he was a baby. His mother was an Indigenous woman; his father was of German ancestry.

There were multiple reports to authorities when Herrmann was a small child, Marsh said, “due to chronic drug and alcohol problems with his parents, domestic violence, emotional abuse and what was described perhaps euphemistically as, ‘failure to meet his basic needs’. This level of neglect was so profound that he and his older sister were reported to have rotten teeth.”

At less than 18 months old, Herrmann was placed in care and admitted to hospital with scabies. At age three, he and his sister were placed in foster care.

Carroll explained the profound psychological impact of his early neglect and how it stunted his brain development. He traced his later distress at his mother failing to turn up to access visits, or arriving drunk. He had no contact with his father while he was in foster care. “He was reared in a chaotic, insecure, dangerous environment that was not responsive to his basic needs.”

This is the manifestation of male rage towards a female Psychiatrist Andrew Carroll

Herrmann has had no positive relationship with men, including his father. At one point, Carroll asked Herrmann about fathers and he said: “I’ve seen them portrayed in the movies, but I don’t really know what they do.” His mother died when he was a teenager.

Even though his foster care was more stable, the early-childhood needs are critical for a child to develop any normal sense of attachment and trust in the world. By the time Herrmann entered primary school he was emotionally fragile, had difficulty forming relationships and harmed other children.

Carroll’s evidence was that Herrmann had a severe personality disorder with particular characteristics. His childhood neglect meant he avoided and suppressed his emotional distress. His unresolved trauma led to a “deep well-spring of sadness and anger” that he had no skills to process. He had distorted assumptions about other people, with “persistent expectations of being exploited, humiliated and belittled” – in middle childhood he had nightmares and slept in a foetal position. Normal functioning was seriously impaired and there was “a sense almost of dissociation, a sense that he just doesn’t matter in the world, that he’s not real in some way”.

There was a “matrix of factors” which led to this crime and Herrmann’s personality disorder – a person’s deficits in thinking, feeling and behaviour, particularly in relation to impulse control and interpersonal behaviour – was exacerbated by heavy cannabis and methamphetamine use that began when he was a teenager. That had a cumulative impact, but he had not taken drugs on the day of the murder.

As a young adult, Herrmann was homeless and unemployed. According to Marsh, Herrmann’s life “followed a rhythm that was essentially, get Centrelink, buy drugs, share them with mates, shoplift food from the supermarket. He subsisted on a diet of croissants and chocolate milk … his lifestyle was one of the pursuit of intoxication through methamphetamine and cannabis.”

Carroll’s evidence was that Herrmann’s personality disorder seriously affected his ability to make judgments and was, with other factors, the underlying reason for the murder. It was an “eruption of suppressed rage” that had built for years. It erupted for some unknown reason on that night, against an innocent woman, with no known trigger. “This is the manifestation of male rage towards a female.”

The reason so long was spent on describing’s Herrmann’s personality disorder is that he has for many years been diagnosed as suffering schizophrenia, and is receiving anti-psychotic meditation.

Carroll disagreed with that diagnosis, but legally a personality disorder is not considered a mental impairment that can be taken into consideration when sentencing in Victoria, under principles known as Verdins.

Marsh, chief counsel at Victoria Legal Aid, argued that a 2015 case – a court of appeal decision known as O’Neill – was wrong to find that such disorders do not influence a sufferer’s perception of the world, and urged Hollingworth to find so. There was no reason why personality disorders – which could seriously affect judgment – should be treated differently to mental illnesses that influence the moral culpability of an offender, such as severe depression or bipolar disorder.

Bourke argued that the very randomness, the brutality, the lack of any motive made this the worst kind of murder justifying a life sentence. The O’Neill decision was correct and Hollingworth sitting as a single judge was bound to follow it. There was “no evidence of the present personality disorder having a causative connection, contribution to the commission of this offence against this girl on this night”.

If a trial is in some way an expression of community feeling and shifting attitudes, perhaps we are at a point where such crimes will be punished by 50 or 60 years in jail, even if they did not attract such severe sentences in the past.

Better off in jail than outside

It was the same issue that confronted the court just a few weeks ago when Jaymes Todd, another young man with no prior convictions, was sentenced to life with a 35-year non-parole period for raping and murdering Eurydice Dixon, 22, as she walked through a suburban Melbourne park.

That was a controversial sentence in legal circles. Victoria Legal Aid funded Todd’s plea hearing, but is not funding his appeal against the sentence – that will be conducted by private barristers pro bono.

In Todd’s case crown prosecutors did not seek a life sentence, but they did in Herrmann’s case. Hollingworth wondered why, when Todd’s was “objectively far more serious offending” given his sexual sadism and stalking of Dixon.

Herrmann is Aboriginal which, as Marsh pointed out, does not make him intrinsically less responsible for his crime and deserving of a more lenient sentence. But it often indicates deprivation and disadvantage, and his background of profound trauma, the instability of his identity and sense of futility could be seen as a mitigating factor in sentencing.

Marsh said Herrmann’s youth indicated rehabilitation was at least possible if the right treatment was offered. His sense of remorse was there, but it was muted. At the very end of the hearing, Herrmann handed Marsh a letter of apology he had written to Maasarwe’s family. “Your daughter didn’t deserve such a terrible and tragic thing to happen to her,” it said. “I don’t expect any forgiveness because I will never be able to forgive myself and I will be trying to make amends for the rest of my life.” It ended: “Don’t give in to hate like I did. Love. Goodbye.”

Marsh said towards the end of the hearing that while it didn’t diminish the loss of the Maasarwe family in any way, there was a second tragedy in the case we should not flinch from: how and why a young man could come to commit such an awful crime.

Herrmann believed he was better off in jail than outside.

“I’ve gained a safe place to sleep,” Marsh said Herrmann told him. “I get fed three times a day, I have a shower, and I’ve also gained a sense of hope that maybe one day if I behave myself in custody I might get to go to a prison that has good programs.”

That such a statement had a whiff of truth to it, said Marsh, was “coming from a place that is so bleak as to defy description”.

Codey Herrmann will be sentenced on 29 October.