It is true if $X$ and $f(X)$ are locally noetherian schemes, and $f$ is an open or closed morphism. See (EGA, IV_2, 5.4.1). Here is the proof when $f$ is open.
By the definition of dimension it is sufficient to prove that for every sequence $(y_i)$ $(0 \le i \le n)$ of distinct points of $f(X)$ with $y_i \in \overline{\{ y_{i+1}\}}$ for $0 \le i \le n-1$, there exists a sequence $(x_i)$ $(0 \le i \le n)$ of points of $X$ such that $x_i \in \overline{\{x_{i+1}\}}$ for $0 \le i \le n-1$ and $f(x_i) = y_i$ for all $i$. The existence of $x_0 \in X$ is clear. Suppose that the points $x_i$ are determined for $i \le m$. Since $f$ is open, and $y_m$ is a specialization of $y_{m+1}$, there exists a point $x_{m+1} \in f^{-1}(y_{m+1})$ such that $x_m$ is a specialization of it. This last fact can be seen by reducing to the affine case. Hence the claim follows inductively.