Consider this matrix:

If a=b, we have identical rows, hence detA=0, so consider a!=b.
Set:

(Why?)
Now A is expressed as:

(Again, why? I can't imagine what is going on here...)
and finally:

Consider this matrix:

If a=b, we have identical rows, hence detA=0, so consider a!=b.
Set:

(Why?)
Now A is expressed as:

(Again, why? I can't imagine what is going on here...)
and finally:

The matrix $A$ can be written as $$ A=(a-b)I+bJ $$ (this is just a simple check), or $$ A=b\left(J-\frac{b-a}{b}I\right) $$ assuming $b\ne0$ (when $b=0$ it's easy to compute $\det A=a^n$).
Now $\det A$ is $b^n$ times the value of the characteristic polynomial of $J$, that is, $$ p_J(X)=\det(J-XI), $$ for $X=\frac{b-a}{b}$.
Since the characteristic polynomial of $J$ is $(0-X)^{n-1}(n-X)$, we get $$ \det A=b^n\left(-\frac{b-a}{b}\right)^{n-1}\left(n-\frac{b-a}{b}\right) =(a-b)^{n-1}(nb-b+a) $$ which agrees with the calculation in your question.
Why the characteristic polynomial of $J$ is $(0-X)^{n-1}(n-X)$? Because $J$ has rank $1$, so $0$ is an eigenvalue with geometric multiplicity at least $n-1)$; but also $n$ is an eigenvalue of $J$ (we assume $n>1$, of course), so the algebraic multiplicity of $0$ must be $n-1$.