Wilson's Theorem: (n-1)! is congruent to -1(mod n) implies that n is prime. I have researched Wilson's theorem several times over stack exchange. I would only like to prove one direction. This seems to be a good explanation: Prove that $(n-1)! \equiv -1 \pmod{n}$ iff $n$ is prime
However, on their explanation, the author states that $k|(n-1)!$ implies that $k$ is congruent to $1$(mod $n$). I don't see their jump in logic. I am looking for either an explanation or a reference to a theorem if possible. Any assistance is appreciated. Thank you
 A: This isn't true in general. For example, $2 | (3-1)! = 2$ but $2$ is not congruent to $1 \pmod 3$. What the author on the question you referenced said was that from the conditions in Wilson's Theorem, $k | (n-1)!$ and also $k$ is congruent to $1 \pmod n$, not that $k | (n-1)!$ implies $k$ is congruent to $1 \pmod n$. 
A: I am not sure how the answer in the linked post derives that
$$ k \equiv 1 \pmod n $$
Instead, here as an alternative way to complete the proof. As in the linked answer, we assume that we have an integer $k$ such that $k<n$ and $k \mid n$. We know that
$$ (n-1)! \equiv -1 \pmod n$$
and so since $k \mid n$
$$ (n-1)! \equiv -1 \pmod k$$
Since $k < n$, we have that
$$ (n-1)! \equiv 0 \pmod k $$
(provided of course that $n>1$)
This gives us that
$$ 0 \equiv -1 \pmod k$$
and so $k \mid 1$ as claimed in the linked answer.
A: As mentioned previously, the implication as you interpreted it is incorrect.  $k\mid (n-1)!$ does not imply that $k\equiv 1\pmod{n}$.  Take any counterexample you like, such as $k=3,n=5$.
Here I hope to go over some of the details of that section of the proof in the attempt to clarify some of the points.
Suppose that $(n-1)!\equiv -1\pmod{n}$
We argue that $n$ must be prime.  To accomplish this, suppose to the contrary that $n$ is in fact composite.  In this case, $n=km$ for some $k,m\in\mathbb{N}\setminus\{1\}$ implying that $k<n$.
In this case, $k$ must then be equal to one of $\{2,3,4,\dots,n-2,n-1\}$.  This implies that $k\mid (n-1)!$ since $(n-1)!=\prod\limits_{i=1}^{n-1} i = k\prod\limits_{i=1~~~i\neq k}^{n-1} i$.
However, since $(n-1)!\equiv -1\pmod{n}$ and $k\mid n$ and $k\mid (n-1)!$, all of these things together imply that $k\equiv 1\pmod{n}$
Why?  Since $k\mid n$ and $k\mid (n-1)!$, you have that $k\mid \gcd((n-1)!,n)$, but since $(n-1)!\equiv -1\pmod{n}$ that implies that $(n-1)!$ is coprime to $n$ (since this implies there is some multiple of $n$ which is exactly one away from $(n-1)!$).  Therefore $\gcd((n-1)!,n)=1$ and so $k\mid 1$.  This is, however, a contradiction since we said that $k\in\mathbb{N}\setminus \{1\}$.
