Officer, by long tradition, were mounted. This allowed them to be seen on the battlefield, and to see across the battlefield, as well. The horse gave them the mobility to traverse their entire "line" of troops. (This is also why so many officer uniforms include riding boots.)
Having a horse is convenient. Unless you drop something. So many things carried while horseback are fitted up with lanyards and retention straps and the like. Swords and sabers has knots, tassels and the like, that retained at the wrist. The first pistols used were single-shot ML, once shot, they needed time that not might be available just now to reload. So, they were left to dangle on a lanyard from the neck (or looped under a shoulder epaulet).
Even after repeating arms became common, keeping the firearm "attached" with a lanyard was still desirable. (Recall, riding a charging horse is slightly complicated as is, if you need one had for a pistol, one hand for a sword, lance, etc., and one hand for the reins. So, the tradition survived. (As did a tradition of only using one hand to shoot, so the lanyard and ring did not interfere with a support hand.)
Even after officers were generally dismounted, the "fashion" of having a lanyard had become tradition. As did the Sam Brown (also Browne) belt with its cross-strap to carry a sword, then, later, a pistol.