The ways to indicate a state or an action which lasted and then ended at or before some point in the past?
I feel quite confused. If I want to say that something was true or was happening for a while before some point in the past, what ways does English give me to express that?
If I want to express that some state was true for a while before some point in the past, which English tense should I use?
"They had been married (Past Perfect) for a while before they divorced in 2019"
"They were married (Past Simple) for a while before they divorced in 2019"
Are the sentences above correct and do they express the same meaning? Or do they have slightly different meanings?
And what about the following two?
"I had been explaining (Past Perfect Progressive) this rule to you for half a lesson before I gave you a test"
"I explained this rule to you for half a lesson before I gave you a test"
Do they both have similar meanings? In contrast, these two sentences are not about a state ("Being married) but they are both about an action, namely - "explaining".
Do I understand correctly that they both seem correct to native-speakers because they are both about an action in the main clause and not about a state? And if there was a state in the main clause, would it be in Past Simple?
You are looking for what old-school grammarians might call the "pluperfect tense". That verb construction describes a state of being in the past in which an action was performed in the even more distant past and was completed.
For example:
I had walked.
As in,
He came to me twenty years ago. At that point in my career, I had walked many thousands of miles already.
To your examples, I think that "They had been married for twenty years when they divorced." (Pluperfect) and "I explained this rule to you for half a lesson before giving you the test." make the most sense. There's a sort of implied "had" in that second sentence, but this construction without it sounds more natural and emphasizes the action rather than it having been completed.
As a general point, here is a brief list of common English verb constructions and their meanings:
In the present:
"I walk." (An action done regularly in the present)
"I am walking." (An action being done right now)
"I have walked." (An action started in the past but completed now, i.e. in the present)
In the future:
"I will walk." (An action to be performed later)
"I will be walking." (An action which will be actively occuring at some - usually specified - later time)
"I will have walked." (An action to be begun and then completed by some time in the future)
In the past:
"I walked." (An action performed in the past)
"I was walking." (An action actively taking place in the past)
"I had walked." (An action both started and completed in the past)