Opportunities to treat a man who went on to kill his best friend following an attempted break-in at Buckingham Palace were missed, a court has heard.