A key idea is clearer this way: $\ x\cdot x = e\,\Rightarrow\, x \color{#c00}{\overset{(1)}=} x^{-1}\, $ so $\ ab \color{#c00}{\overset{(1)}=} \color{blue}{(ab)^{-1}}\! \color{#0a0}{\overset{(2)}=} b^{-1} a^{-1}\! \color{#c00}{\overset{(1)}=} b a\ \ \,$ QED
Now it is clearer where the proof "comes from", namely it arises by "overlapping" the identities $x\! \color{#c00}{\overset{(1)}=} x^{-1}$ and $\,(xy)^{-1}\color{#0a0}{\overset{(2)}=} y^{-1} x^{-1}$ i.e. by discovering some term $\,\color{blue}{(ab)^{-1}}\!$ where both identities apply. Then, just as we did above, we can rewrite the term in two ways, giving a possibly new equality.
This is a widely applicable method of deriving consequences of identities, i.e. by "unifying" terms of both so that both identities apply. In fact in some cases it can be used to algorithmically derive all of the consequences, so yielding algorithms for deciding equality, e.g. see the Knuth-Bendix equational completion algorithm and the Grobner basis algorithm, and see George Bergman's classic paper The Diamond Lemma in Ring Theory.