Prince William told a group of emergency service personnel that he felt "lonely" after he left his "traumatic" job as an air ambulance pilot.