If you want to define "Matrix" as a new Atom, your approach works.
E.g. let us define matrices a0 and a1 that commute:
a0 = RandomReal[{-1, 1}, {2, 2}];
a1 = a0 . a0;
and also a matrix that does not commute:
b = RandomReal[{-1, 1}, {2, 2}];
If we now define "Matrix":
Clear[Matrix]
Unprotect[Times];
Matrix[x_] Matrix[y_] /; x . y == y . x ^= Matrix[x . y];
Protect[Times];
We get for the product of 2 commuting matrices:
Matrix[a0] Matrix[a1]
(* Matrix[{{0.090018, -0.15005}, {-0.276659, 0.0619167}}] *)
and for non-commuting matrices:
Matrix[a0] Matrix[b]
(* Matrix[{{-0.725916, -0.626387}, {-0.553722, -0.871338}}] \
Matrix[{{0.114884, -0.425647}, {-0.784798, 0.0351695}}] *)
Unprotect
andProtect
Times
. UseTagSetDelayed
rather thanTagSet
.Matrix /: Matrix[x_] * Matrix[y_] := Matrix[x.y] /; x.y == y.x;
$\endgroup$