In a right triangle XYZ where angle X is 90 degrees, we can use the information provided to find the cosine of angle Z.
Given that tan Z = 3, we know that:
\[ \tan Z = \frac{\text{opposite}}{\text{adjacent}} = \frac{YZ}{XZ} = 3.\]
Since triangle XYZ is a right triangle, we can use the Pythagorean theorem:
\[ XY^2 + YZ^2 = XZ^2.\]
Since angle X is 90 degrees, we have:
\[ XZ^2 = XY^2 + YZ^2 = YZ^2 + YZ^2 = 2YZ^2.\]
Solving for YZ:
\[ YZ^2 = \frac{XZ^2}{2}.\]
Since we know the value of YZ/XZ (which is the tangent of angle Z):
\[ \tan Z = \frac{YZ}{XZ} = 3.\]
Squaring both sides:
\[ YZ^2 = 9XZ^2.\]
Now, substituting the value of YZ^2 from the Pythagorean theorem:
\[ 9XZ^2 = \frac{XZ^2}{2}.\]
Solving for XZ:
\[ \frac{XZ^2}{2} = 9XY^2.\]
\[ \cos Z = \boxed{\frac12}.\]