Direct imaging and dynamical mass of a benchmark T-type brown dwarf companion to HD 167665