The mechanism of the above reaction has not been resolved, but it has been suggested that  is found in its ionic form  and the reaction proceeds via nucleophilic attack of  by  (from  dissociation). Elimination of HCl (the major side product) creates a reactive nucleophilic intermediate
which through further attack of  and subsequent HCl elimination, creates a growing acyclic intermediate
:, etc.
until an eventual intramolecular attack leads to the formation of one of the cyclic oligomers.