The density can be integrated with respect to $y$ and then inverted, which allows the inverse transform sampling method https://en.wikipedia.org/wiki/Inverse_transform_sampling to be used to generate random numbers from the distribution having the density $f(y|z)$.
First of all, note that in order to make $f(y|z)$ a proper density, i.e., integrating to 1 over its domain, the needed condition is $0 \le y \le z$, not $0 \lt y \lt \kappa$.
The cumulative distribution $$F(y|z) = -(exp(\kappa*z)-1-exp(-\kappa*(y-z))+exp(-\kappa*y))/((exp(\kappa*z)-1)*(-1+exp(-\kappa*z)))$$ for $0 \le y \le z$. Note that $F(0|z) = 0$ and $F(z|z) = 1$.
This can be inverted, resulting in $$ln(1/(U-exp(\kappa*z)*(U-1)))/\kappa+z$$ as the formula to generate a random number from a distribution having density $f(y|z)$, where $U$ is a random number drawn from a $Uniform[0,1]$ random number generator. For each random number to be drawn from the distribution having density $f(y|z)$, a single value of $U$ is drawn, and this single value is used in both locations in which it appears in the formula.
As can be seen, $U$ values of $0$ to $1$ produce random numbers via the formula ranging from $0$ to $z$.