Toroidally magnify-blur a matrix
APL (Dyalog Extended), 27 26 bytes

-1 thanks to Bubbler.

Anonymous infix lambda. Takes \$n\$ as left argument and \$M\$ as right argument.



{⊃+⌿,(⍳⍺)⍉⍤⌽\⍣2⊂⍺/⍺⌿⍵÷⍺*2}


Try it online! (the \$n=100\$ case run out of memory on TIO gives by default, but works offline)

{…} "dfn"; ⍺ is \$n\$ and ⍵ is \$M\$

 ⍺*2 \$n^2\$

 ⍵÷ \$M\over n^2\$

 ⍺⌿ replicate vertically so each row becomes \$n\$ copies

 ⍺/ replicate horizontally so each column becomes \$n\$ copies

 ⊂ enclose to work on entire matrix

 (⍳⍺)…⍣2 do the following twice, each time with the \$0,1…n-1\$ as left argument:

  \ outer "product" using the following tacit function instead of multiplication:

   ⌽ cyclically rotate the rows by the indices

   ⍤ then:

    ⍉ transpose

 , flatten

 +⌿ sum

 ⊃ disclose (since the summation reduced rank from 1 to 0 by enclosing)