If, for example, I write that some territory belonged to some country until 1954, should I use Past Perfect ('had belonged')? Is it optional?
You should use past perfect tense when you are describing a series of events in the past. For example, if you consider describing what happened after 1954, then you must use past perfect tense, provided you are speaking about/related to the same concept or story-line.
The territory had belonged to the Empire until 1954, after which it went into the hands of the barbarians.
If you wish to depict/describe only a single event in the past, then you must consider using simple past tense.
The territory belonged to the Empire until 1954.
For more reference and examples, you can read this article.