I always understood that the expression heir and spare came about a few hundred years ago when the country had a great number of very large estates.
The owners were always concerned that their wealth and land would disappear to distant ( and in their minds, unworthy) relatives should the incumbent die without leaving at least two sons to ensure the unthinkable did not happen. If the deceased left only daughters they could not inherit, unlike the Royal family.
I don’t recall any historical references to the term being used in relation to the Royal Family, until the birth of Harry, when The Princess of Wales used it. I certainly have no recollection of Princess Margaret or Prince Andrew (prior to Prince Charles’s birth) being referred to as the spare. The term initially applied to the Queen after George Vth came to the throne was Heiress Presumptive, as opposed to Apparent, in case her mother should have a late baby who turned out to be a son.