It's not // was to // , but rather // was // to spend //. The verb is "to spend", and the word "was" marks it as being in the past tense, but it's a special kind of past tense:
In the past, but looking towards the future
This is the past tense, but speaking of an event that is later than the tense of the sentence, and is rather unsurprisingly known as the future-in-the-past tense.
In your example sentence, the action (to spend four years in Bangalore) is something that happened in the past, but it had not yet happened at the point in time described by the sentence. Think of this tense as describing the moment before a past action started.
This is a favourite tense of historians, because history writing often involves standing in a particular point in time, and looking ahead to the consequences of an event, or the later life of a protagonist.
There are two common forms of this tense. The one you quote is possibly the rarer one, and is more formal. Most commonly, this tense is formed by putting "would" in front of the present-tense verb, as in this rewrite of the original sentence:
He would spend most of the next four years of his life with the Regiment in Bangalore and the North West Frontier in India.
Yes, this does look very like the conditional future tense, but there's a difference: this sentence doesn't have the "but", "if", "except" clause that would be needed to make it a conditional sentence, so it can only be the future-in-the-past.
You might also have noticed that if you use the "would" form, you must follow with the present-tense of the verb; but with the "was" form, you had to use the infinitive (so it's "was to spend", but "would spend").
Incidentally, there is also a present-tense equivalent of this, that we could call a "future-in-the-present" tense, as in these equivalent sentences:
- According to sources, she is to resign the position of party leader.
- According to sources, she will resign the position of party leader.
The difference between these is very slight, but in Number 1., we have more of a sense that the action is going to happen almost immediately, where 2. makes no real promise about when. Both can be used in sentences that specify an exact time, in which case they're identical in meaning:
- According to sources, she is to resign the position of party leader tonight.
- According to sources, she will resign the position of party leader tonight.