For any ordinal $\lambda$, $cof(\lambda)$ is the least cardinal $Cf(\lambda)$ of a cofinal subset of $\lambda$.
Indeed, by definition, since for any ordinal $\alpha$, $|\alpha| \leq \alpha$, $cof(\lambda) \leq Cf(\lambda)$.
If $\lambda$ has a greatest element, both of them are $1$, and if $\lambda$ is empty, both of them are $0$, so in the following I assume $\lambda$ is limit non zero.
Now let $C$ be a cofinal subset of $\lambda$ of cardinal $Cf(\lambda)$. Fix a surjection $c: Cf(\lambda) \rightarrow C$. We want to define a subset $D:=\{d_{\alpha} \ | \ \alpha < Cf(\lambda)\}$ of $\lambda$ order type $Cf(\lambda)$ which is cofinal in $\lambda$. This can be done by induction: if the $d_{\beta}$ are defined below a certain ordinal $\alpha < Cf(\lambda)$, then by minimality of $Cf(\lambda)$, $\{d_{\beta} \ |\ \beta < \alpha\}$ has an upper bound in $\lambda$, and since $\lambda$ doesn't have a greatest element, it has a strict upper bound $\delta$, we define $d_{\alpha} := \max(\delta, c_{\alpha})$. By construction, $\alpha \mapsto c_{\alpha}$ is strictly increasing (because $d_{\alpha} \geq \delta$) and cofinal (because $d_{\alpha} \geq c_{\alpha}$ and $C$ is cofinal). So $Cf(\lambda) \leq cof(\lambda)$.
This anwsers your question: for $f: \lambda \rightarrow \kappa$, $|f(\lambda)| \leq \lambda < cof(\kappa) = Cf(\kappa)$ so $f(\lambda)$ is not cofinal in $\kappa$.
There are several important and basic properties of the cofinality / of regular ordinals which I suggest you look into:
-every regular ordinal is a cardinal (this follows easily from the result above)
-every successor infinite cardinal is regular
-the cofinality of an ordinal is regular
-the cofinality of an ordinal is the only regular ordinal among the order types of cofinal subsets of that ordinal