Prince William's royal equerry - appointed by the royal household in 2020 - is leaving the post to return to the navy.