I have the linear transformation
$T \in \mathcal{L}(\mathbb{C}^{5})$ defined by $T(x_1,x_2,x_3,x_4,x_5)=(2x_1,x_2+x_4,2x_3,x_2+x_4,-x_1+x_3+2x_5)$
The matrix with respect to the standard basis is $A=\begin{bmatrix} 2&0&0&0&0\\ 0&1&0&1&0\\ 0&0&2&0&0\\ 0&1&0&1&0\\ -1&0&1&0&2\end{bmatrix}$
I know the eigenvalues are $2$ and $0$. The eigenspaces are $E(0,T)=\{(0,x_2,0,-x_2,0,0):x_2 \in \mathbb{C}\}$
$E(2,T)=\{(x_1,x_2,x_1,x_2,x_5):x_1,x_2,x_5 \in \mathbb{C}\}$
I considered the matrix $(A-2I)^5$ which I found on my calculator to be
$(A-2I)^5=\begin{bmatrix} 0&0&0&0&0\\ 0&-16&0&16&0\\ 0&0&0&0&0\\ 0&16&0&-16&0\\ 0&0&0&0&0\end{bmatrix}$
I then calculated the null space of this matrix to yield the generalized eigenspace: $G(2,T)=\{(x_1,x_2,x_3,x_2,x_5):x_1,x_2,x_5 \in \mathbb{C}\}$
In a linear algebra book they give an example with the matrix,
In the example they give the matrix
A=$\begin{bmatrix} 3&1&-2\\ -1&0&5\\ -1&-1&4 \end{bmatrix}$
They claim a basis of the null space of $(A-2I)^2$ is
$\begin{bmatrix} 1\\ -3\\ 1 \end{bmatrix}, \begin{bmatrix} -1\\ 2\\ 0 \end{bmatrix} $
However when calculating the way I did with the first matrix I get
$\begin{bmatrix} 1/2\\ 1\\ 0 \end{bmatrix}, \begin{bmatrix} -1/2\\ 0\\ 1 \end{bmatrix} $
as a basis for the generalized eigenspace.
I am wondering why in the first example I have given I can just calculate $\text{null}(A-5I)^5$ to give me the generalized eigenvectors. In other examples I have seen they were not able to do this, Which method is correct?
I thought you cannot just calculate the null space of $(A-\lambda I)^{\text{dimV}}$ to get the generalized eigenspace for a matrix of a linear map with $V$ as the domain.
Since you don't have shown your calculations, I can't tell you where the mistake is. Furthermore, the solutions from the book you have quoted are wrong.
The matrix $A$ has two linearly independent eigenvectors, take for instance $(-1, 3, 1)$ and $(-1, 2, 1)$. Furthermore, note that
$$(A - 2I)^2 = \begin{pmatrix} 2 & 1 & -1 \\ -4 & -2 & 2 \\ -2 & -2 & 1 \end{pmatrix}.$$
A row-reduced echelon from of this matrix is
$$\begin{pmatrix} 2 & 1 & -1 \\ 0 & -1 & 0 \\ 0 & 0 & 0 \end{pmatrix}.$$
You now can choose $(1, 0, 2)$ as a generalized eigenvector.