As already explained, this happens because MatrixForm act as a wrapper.
The answer to the question about how this behavior is implemented and how can eventually be reproduced is contained in the Informmation of the system symbol $OutputForms. Indeed
?? $OutputForms
returns:
$OutputForms is a list of the formatting functions that get stripped
off when wrapped around the output.
and
$OutputForms={InputForm,OutputForm,TextForm,CForm,Short,Shallow,MatrixForm,TableForm,TreeForm,FullForm,NumberForm,EngineeringForm,ScientificForm,QuantityForm,PaddedForm,AccountingForm,BaseForm,DisplayForm,StyleForm,FortranForm,ScriptForm,MathMLForm,TeXForm,StandardForm,TraditionalForm}
As noted earlier, this affects what the kernel stores in the output history when it encounter a result with any of the previous Head.
For example:
Unprotect[$OutputForms];
AppendTo[$OutputForms, foo];
foo[1]
Head[%]
foo[1]
Integer
I discovered this last summer while working on a way to better show rational matrices: if interested please see this question. I ended up writing my own PrettyMatrixForm with the same output behavior as one of the previous XyzForm.
Outis special. Here's another special case:1;clearly evaluates toNullyet the value assigned to the correspondingOutexpression will be1. A related question would be: how can we create our own function or wrapper that influences that value assigned toOut? – Szabolcs Mar 17 '14 at 18:35mat//MatrixForm;nowOutgets assigned theMatrixForm. – george2079 Mar 17 '14 at 18:461;I find especially troubling! Compare the behavior of that with that ofa; bwhich has outputband then%also givesb. So why doesn't1;then%give either nothing or elseNull? – murray Mar 17 '14 at 21:591;as1;Null. Well, I guess this is a useful feature but a bit weird. I learned about it on MathGroup. I was also very surprised. – Szabolcs Mar 17 '14 at 22:04