A teenager travelled more than 150 miles to confront and fatally stab a man his family had accused of stalking, a court has heard.