An algebraic theory about semiclassical and classical matrix orthogonal polynomials