How can we stop this?
We can't. There will always be people who are mentally unwell or just plain nasty, even in the most perfect society. Humans are flawed.
What we could do to help reduce incidents like this is to massively improve mental health services in the UK and offer more support to those who are dealing with difficult situations such as family break-ups.
We could target those who are themselves victims of abuse, and watch for worrying behaviours in young people and get to them early before they grow up and do something horrible.
We won't, because it's too expensive and society tends to look on these people as "evil", which might make them feel good but does bugger all to address the issue.