This question is about sentences that begin with adverbials with a negative meaning. In these sentences, the subject and the auxiliary verb are inverted. You can find other examples with only here: only if, only after, only then, etc and not until. For details of other negative adverbials, for example under no circumstances, see the Oxford Guide to English Grammar, page 27.
You can only play after lunch.
Only after lunch can you play
This same inversion is much more common for questions and negatives, so these are much better understood and documented. Here is an example:
He can play the piano.
Can he play the piano?
But what happens if you need to invert and there is no auxiliary verb? The answer is that you insert do as an auxiliary verb, and then swap it.
He ... plays the piano.
He does play the piano.
Does he play the piano?
In your first sentence, there is no auxiliary verb so it is necessary to add did before the subject I. In the second sentence, would is the auxiliary verb, so there is no need to add do: you just move would before the subject (they).