A man who killed his friend on Christmas Eve in Cardiff previously tried to break into Buckingham Palace, a court has heard.