Jelly, 5 bytes
Z⁹Ƥ⁺€
Uses the 4D output format. For 3D, append a Ẏ
for 6 bytes.
How it works
Z⁹Ƥ⁺€ Main link. Left argument: M (matrix). Right argument: n (integer)
⁹Ƥ Apply the link to the left to all infixes of length n.
Z Zip the rows of the infix, transposing rows and columns.
⁺€ Map Z⁹Ƥ over all results.