The problem can be attacked via Inclusion-Exclusion. See this article for an
introduction to Inclusion-Exclusion.
Then, see this answer for an explanation of and justification for the Inclusion-Exclusion formula.
Label the non-zero cells $~C_1, C_2, C_3.~$
Let $~S~$ denote the set of all possible placements of $~C_1, C_2, C_3.~$
Let :
$S_1~$ denote the subset of $~S~$ where cells $~C_1,C_2~$ are adjacent.
$S_2~$ denote the subset of $~S~$ where cells $~C_1,C_3~$ are adjacent.
$S_3~$ denote the subset of $~S~$ where cells $~C_2,C_3~$ are adjacent.
Then, the desired computation is
$$| ~S ~| - | ~S_1 \cup S_2 \cup S_3~|. \tag1 $$
Let:
$T_0~$ denote $~| ~S ~|.~$
$T_1~$ denote $~| ~S_1 ~| + | ~S_2 ~| + | ~S_3 ~|.~$
$T_2~$ denote $~| ~S_1 \cap S_2 ~| + | ~S_1 \cap S_3~| + | ~S_2 \cap S_3 ~|.~$
$T_3~$ denote $~| ~S_1 \cap S_2 \cap S_3 ~|.~$
Then, in accordance with Inclusion-Exclusion theory, the computation in (1) above is equivalent to
$$\sum_{r=0}^3 (-1)^r T_r. \tag2 $$
Considerations of symmetry will simplify the computations in (2) above.
$$T_0 = | ~S ~| = \binom{n^2}{3}. \tag3 $$
By considerations of symmetry, $~\displaystyle T_1 = \binom{3}{1} \times | ~S_1 ~|.$
To compute $~S_1,~$ you must categorize the possible placements of cell $~C_1.~$ Cell $~C_1~$ may be placed in:
One of the 4 corners:
Then, there are $~3~$ possible placements for cell $~C_2,~$ and then $~(n^2 - 2)~$ possible placements for cell $~C_3.~$ So, the partial sum represented by this category is $~4 \times 3 \times (n^2 - 2).~$
One of the edge rows or columns, except one of the 4 corners.
So, $~C_1~$ can go in $~4(n-2)~$ different positions.
Then, there are $~5~$ possible placements for cell $~C_2,~$ and then $~(n^2 - 2)~$ possible placements for cell $~C_3.~$ So, the partial sum represented by this category is $~4(n-2) \times 5 \times (n^2 - 2).~$
One of the inner cells.
So, $~C_1~$ can go in $~(n-2)^2~$ different positions.
Then, there are $~8~$ possible placements for cell $~C_2,~$ and then $~(n^2 - 2)~$ possible placements for cell $~C_3.~$ So, the partial sum represented by this category is $~(n-2)^2 \times 8 \times (n^2 - 2).~$
Therefore,
$$T_1 = 3 \times (n^2 - 2) \times \left\{ ~[ ~12 ~] + [ ~4(n-2) \times 5 ~] + [ ~(n-2)^2 \times 8 ~] ~\right\}. \tag4 $$
The analysis in this section will piggyback off of the previous section.
By considerations of symmetry, $~\displaystyle T_2 = \binom{3}{1} \times | ~S_1 \cap S_2 ~|.$ The $~| ~S_1 \cap S_2 ~| ~$ computation represents all of the possible ways that cell $~C_1~$ can be simultaneously adjacent to cells $~C_2~$ and $~C_3.~$
To compute $~| ~S_1 \cap S_2 ~|,~$ you must categorize the possible placements of cell $~C_1.~$ Cell $~C_1~$ may be placed in:
One of the 4 corners:
Then, there are $~(3 \times 2)~$ possible placements for cells $~C_2~$ and $~C_3.~$ So, the partial sum represented by this category is $~4 \times 6.~$
One of the edge rows or columns, except one of the 4 corners.
So, $~C_1~$ can go in $~4(n-2)~$ different positions.
Then, there are $~(5 \times 4)~$ possible placements for cells $~C_2~$ and $~C_3.~$ So, the partial sum represented by this category is $~4(n-2) \times 20.~$
One of the inner cells.
So, $~C_1~$ can go in $~(n-2)^2~$ different positions.
Then, there are $~(8 \times 7)~$ possible placements for cells $~C_2~$ and $~C_3.~$ So, the partial sum represented by this category is $~(n-2)^2 \times 56.~$
Therefore,
$$T_2 = 3 \times \left\{ ~[ ~24 ~] + [ ~4(n-2) \times 20 ~] + [ ~(n-2)^2 \times 56 ~] ~\right\}. \tag5 $$
Very similar piggybacking off of the previous section will be used to compute $~T_3 = | ~S_1 \cap S_2 \cap S_3 ~|.~$ Here, you need each of the three cells $~C_1, ~C_2, ~C_3,~$ to be adjacent to both of the other two cells. Again, categories of the $~C_1~$ placement will be used.
Cell $~C_1~$ may be placed in:
One of the 4 corners:
Then, there are $~(3 \times 2)~$ possible placements for cells $~C_2~$ and $~C_3,~$ where mutual adjacency is preserved. So, the partial sum represented by this category is $~4 \times 6.~$
One of the edge rows or columns, except one of the 4 corners.
So, $~C_1~$ can go in $~4(n-2)~$ different positions.
Of the $~(5 \times 4)~$ possible placements in this category, in the previous section, exactly $~12~$ of them preserve mutual adjacency. So, the partial sum represented by this category is $~4(n-2) \times 12.~$
One of the inner cells.
So, $~C_1~$ can go in $~(n-2)^2~$ different positions.
Of the $~(8 \times 7)~$ possible placements in this category, in the previous section, exactly $~24~$ of them preserve mutual adjacency. So, the partial sum represented by this category is $~(n-2)^2 \times 24.~$
Therefore,
$$T_3 = [ ~24 ~] + [ ~4(n-2) \times 12 ~] + [ ~(n-2)^2 \times 24 ~]. \tag6 $$
So, the final computation can be determined by feeding the expressions from (3) through (6) above, into (2) above.