There is no reason you couldn’t use the simple past tense in the first example.
I explained this rule to you for half a lesson before I gave a test
There is also no reason you couldn’t use the past perfect tense in the second sentence.
They had been married for a few years before divorcing in 2016.
These are both grammatical, as are your original ...
If you want to talk about an action as something that caused something, then the action is functioning as a noun (it's a thing that is doing stuff). A noun formed from a verb is a gerund. So it would be "Spending my life ..."
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.
I had walked.
He came to me twenty years ago. At that point in my career, I had walked many thousands of ...
[a dialogue often illustrates usage more clearly]
Just to show how English might actually be spoken:
John: They'd been married for a few years before they got a divorce in 2009.
Mary: No, they hadn't. That's wrong.
John: You mean they'd been living together? Is that it?
Mary: Well, they might have been, I'm not sure. But one thing's for sure. They hadn't ...