Using Matlab, I randomly generate matrix $A \in \Bbb C^{2 \times 1}$ and compute its pseudo-inverse $A^{+}$. I notice that $AA^{+} \neq I$, and yet $\mbox{Tr}(AA^{+}) = 1$.
For other sizes it seems like the trace is equal to the smaller dimension of $A$. I couldn't find this property explained. Could anyone help me understand these two facts?
Suppose you generate $A\in\mathbb{C}^{m\times n}$ randomly, as you specified. Then $\text{rank}(A)=\min\{m,n\}$ with high probability (depending on the probability distribution you used, of course). Now, if $A$ has rank $m$, then $AA^*\in\mathbb{C}^{m\times m}$ has rank $m$ and is invertible. Therefore, the Moore-Penrose pseudoinverse $A^\dagger = A^*(AA^*)^{-1}$ can be used to actually "obtain" $I$ through right-inversion, i.e., $AA^\dagger=I_m$. Similarly, if $\text{rank}(A)=n$, then $A^*A\in\mathbb{C}^{n\times n}$ is invertible, and $A^\dagger = (A^*A)^{-1}A^*$ is a left inverse of $A$; $A^\dagger A = I_n$.
Note that if $\text{rank}(A)=n<m$, then for all $B\in\mathbb{C}^{n\times m}$ it holds that
$$\text{rank}(AB)\le \min\{\text{rank}(A),\text{rank}(B)\}=\min\{n,\text{rank}(B)\}\le n < m$$
and therefore the matrix $AB\in\mathbb{C}^{m\times m}$ cannot possibly equal the identity (which has rank $m$). A similar remark holds in the case that $\text{rank}(A)=m<n$, namely, that there is no left inverse.
Therefore, for your example of $A\in\mathbb{C}^{2\times 1}$, you cannot expect there to be a right inverse of $A$, since $AB$ will be of rank-1 for all $B\in\mathbb{C}^{1\times 2}$. However, you should be able to find a left inverse (a vector that has inner product equal to one with $A$).
As per your question regarding trace: are you using MATLAB's
pinvfunction? If so, it will compute whichever Moore-Penrose inverse "makes sense". In other words, for your matrix $A\in\mathbb{C}^{2\times 1}$, the MATLAB function will compute a left pseudo-inverse $A^\dagger\in\mathbb{C}^{1\times 2}$. In this case, $A^\dagger A$ should equal to $I_1=1$. Furthermore, by the cyclic property of the trace, using the left inverse on the "wrong side" (the right), you will still get a trace of one, since $\text{tr}(AA^\dagger)=\text{tr}(A^\dagger A) = \text{tr}(1)=1$.More generally, suppose $A\in\mathbb{C}^{m\times n}$ has rank $n<m$ (and therefore is left-invertible). Then the left Moore-Penrose pseudoinverse $A^\dagger=(A^*A)^{-1}A^*$ when used on the right will give
$$\text{tr}(AA^\dagger) = \text{tr}(A^\dagger A) = \text{tr}((A^*A)^{-1}A^*A)=\text{tr}(I_n) = n$$
as per your observation.