Why the construction "They it was who..." is grammatically correct?

Solution 1:

Yes, it is grammatical. The complement of the copula ('they') is fronted for emphasis. It can be used with other pronouns ("He it was... "), and equally with names ("John it was who ... ") but I think it is less common with other kinds of noun phrase.