We adopt the system of units in which speed of light is 1.
Components of the stress tensor $T^{\alpha\beta}$ physically mean the following: $T^{00}$ is the energy density, $T^{0j}$ is the energy flux across the spatial-surface $x_j=$ constant ($j=1,2,3$), $T^{i0}$ is the density of $i$-th component of momentum, and $T^{ij}$ is the $i$-th component of momentum flux across the spatial-surface $x_j=$ constant ($i,j=1,2,3$). Normal momentum flux ($T^{ij}$ for $i=j$) causes normal stress on the fluid element and the others ($T^{ij}$ for $i\neq j$) cause shear stress on the fluid element.
An ideal fluid is one whose viscosity and conductivity are zero. Consider an elemental volume of ideal fluid in its MCRF (momentarily co-moving reference frame). Since conductivity is zero, there is no energy flux into or out of it, which implies $T^{0j}=0$. Since there is no viscosity, it doesn't experience shear stresses, therefore $T^{ij}=0$ when $i\neq j$. Further the statement that the fluid has no viscosity is a frame-independent statement, so $T^{ij}=0$ when $i\neq j$ in any reference frame, and so the matrix $T^{ij}$ must be diagonal in all reference frames. This is possible only if $T^{ij}=p\delta^{ij}$ in which $\delta^{ij}$ is the identity tensor and $p$ is a scalar called pressure. If we denote the energy density by $\rho$, then the stress tensor $T^{\alpha\beta}$ in the MCRF of the fluid element is:
$$\begin{bmatrix}
\rho & 0 & 0& 0\\
0 & p& 0& 0\\
0 & 0& p& 0\\
0 & 0& 0& p
\end{bmatrix}$$
This can be simplified as:
$$\begin{bmatrix}
\rho & 0 & 0& 0\\
0 & p& 0& 0\\
0 & 0& p& 0\\
0 & 0& 0& p
\end{bmatrix}=
\begin{bmatrix}
\rho+p & 0 & 0& 0\\
0 & 0& 0& 0\\
0 & 0& 0& 0\\
0 & 0& 0& 0
\end{bmatrix}+
\begin{bmatrix}
-p & 0 & 0& 0\\
0 & p& 0& 0\\
0 & 0& p& 0\\
0 & 0& 0& p
\end{bmatrix}\\
\Rightarrow\quad T^{\alpha\beta}=(\rho+p)(\mathbf{e}_0\mathbf{e}_0)^{\alpha\beta}+p\eta^{\alpha\beta}$$
in which $\eta^{\alpha\beta}$ is the metric tensor. The unit vector in the time direction (of the MCRF of the fluid element) $\mathbf{e}_0$ is nothing but its 4-velocity $\mathbf{U}$. Therefore the dyadic $\mathbf{e}_0\mathbf{e}_0=\mathbf{U}\mathbf{U}$, whose component is $(\mathbf{U}\mathbf{U})^{\alpha\beta}=U^\alpha U^\beta$. Thus we have:
$$T^{\alpha\beta}=(\rho+p)U^\alpha U^\beta+p\eta^{\alpha\beta}$$
Reference: General Relativity by B. Schutz.