During the Napoleonic wars the ranks of junior infantry officers were captain, lieutenant and ensign. The only regiments to use 2nd Lieutenant as a rank, as far as I know, were the rifle regiments (since they did not carry colours and the rank of ensign therefore was less appropriate). Ensigns did not only carry colours, since there was one ensign per company but the junior two in the battalion were called on to do this.
The cavalry simarly had captain, lieutenant and cornet. Their regimental standards and squadron guidons were (and still are) carried by sergeant majors.
In most cases therefore the term second lieutenant refers to the appointment (not the rank) of the most junior lieutenant, if there were actually two with the company.
The same system was used for majors within battalions whenever two were present. The Royal Artillery had second captains within batteries.
It is no different to the Royal Navy system of having a number of lieutenants per warship. They were all the same rank of lieutenant but referred to in order of seniority as first lieutenant, second lieutenant, third lieutenant etc.
Most regiments of the British Army later (I think after the Napoleonic wars) changed the rank of ensign to 2nd Lieutenant. As far as I recall the Guards did not change and still refer to their 2nd Lieutenants as Ensigns. Some cavalry regiments still refer to their 2nd Lieutenants as Cornets. Those traditions are part of what still gives every British Army regiment a distinct identity which they try hard to preserve against all attempts at standardisation.