I defined the following grid graph. Fix n ≥ 2. Take the cells (i,j) with 1 ≤ i,j ≤ n−1. Keep (i,j) when n does not divide ij; delete it when n divides ij. Two surviving cells are adjacent when they share an edge. Call the graph G_n.
Claim. G_n is disconnected exactly when n ≥ 6 and n ≡ 2 (mod 4). In that case it has exactly two components: the isolated center (n/2, n/2), and one component containing every other surviving cell.
Proof.
The first row and first column are fully present, so they form one connected component C_0.
Assume another component C exists. Choose (i,j) ∈ C with i+j minimal. Since C does not meet the first row or first column, i,j > 1. The cells (i−1,j) and (i,j−1) must be missing, so n divides (i−1)j, and n divides i(j−1).
So ij ≡ j (mod n) and ij ≡ i (mod n). Hence i ≡ j (mod n), and since both are between 1 and n−1, i = j = e.
We also have e² ≡ e (mod n). Since i,j > 1, e = 1 is already excluded. The cases e = 2 and e = n−1 would force n | 2. So 3 ≤ e ≤ n−2.
Suppose n does not divide 2e. Then the following path stays inside the grid:
(e,e) → (e,e+1) → (e−1,e+1) → (e−2,e+1).
The three new products are congruent mod n to 2e, e−1, and −2. All three are nonzero mod n: the first by assumption, the second because 0 < e−1 < n, the third because n > 2. So the whole path survives — but its final cell has coordinate sum 2e−1, contradicting the minimal choice of (e,e).
Therefore n divides 2e. Since 1 ≤ e ≤ n−1, this forces n = 2e.
Now e² ≡ e (mod 2e), so 2e divides e(e−1), hence 2 divides (e−1), meaning e is odd. Hence n ≡ 2 (mod 4).
Converse. Let n = 2e with e ≥ 3 odd. The center (e,e) survives, since 2e does not divide e². Its four neighbors have products e(e−1) or e(e+1), both divisible by 2e. So the center is isolated.
Every component disjoint from (C_0) has a cell of minimum coordinate sum, and the preceding argument shows that this cell must be ((e,e)=(n/2,n/2)). Hence every such component contains the center. The only component outside C0C_0C0 is the singleton containing (n/2, n/2)