Not sure if I understand but maybe you want something like this?
(* Repeat setup sand name the resulting 5x5 *)
kernel = {{0, 1, 0}, {1, -4, 1}, {0, 1, 0}};
vals = Array[f, {5, 5}];
laplacian = ListConvolve[kernel, vals, {2, -2}, 0];
Now we regard this as 25 expressions in 25 variables and extract the coefficient arrays. The first is the (missing) constants, which would be the right hand side in an inhomogeneous equation of the form mat.x==b
. We ignore it here (it's all zeros).
lapOperator = CoefficientArrays[Flatten@laplacian, Flatten@vals][[2]]
(* Out[571]= SparseArray[< 105 >, {25, 25}] *)
The sparse array form is probably preferable for actual use, but if you want to see what it looks like here it is in full matrix form.
Normal[lapOperator]
(* Out[572]= {{-4, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0}, {1, -4, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, -4, 1, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, -4, 1, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, -4,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0,
0, 0, 0, -4, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 1, 0, 0, 0, 1, -4, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 1, -4, 1, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 1, -4, 1, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {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