[guided]Replacement is the only axiom where closure under finitely many rank operations is not enough. We must prove that a whole definable image of a set still has rank bounded below $\kappa$.
Fix a formula $\varphi(x,y,p_1,\dots,p_n)$ and parameters $a,p_1,\dots,p_n\in V_\kappa$. Assume that inside $M$ the formula defines a unique output for each input in $a$:
\begin{align*}
M\models \forall x\in a\,\exists!y\,\varphi(x,y,p_1,\dots,p_n).
\end{align*}
Define the ambient function
\begin{align*}
F:a&\to V_\kappa
\end{align*}
by sending each $x\in a$ to the unique $y\in V_\kappa$ such that $M\models \varphi(x,y,p_1,\dots,p_n)$. This is a genuine set function in the ambient universe: the domain $a$ is a set, the structure $M$ is a set structure, and the defining satisfaction relation is fixed.
By ambient Replacement, the image
\begin{align*}
B:=F[a]=\{F(x):x\in a\}
\end{align*}
is a set. The remaining question is not whether $B$ exists in $V$; it does. The question is whether $B$ has rank below $\kappa$, so that $B\in V_\kappa$.
For each $x\in a$, define the ordinal
\begin{align*}
\rho(x):=\operatorname{rank}(F(x)).
\end{align*}
Because $F(x)\in V_\kappa$, each $\rho(x)$ is below $\kappa$. We now need one ordinal below $\kappa$ that bounds all these ranks at once.
This is where regularity of $\kappa$ enters. First, $a$ has size less than $\kappa$. To see this, choose $\alpha<\kappa$ with $a\subset V_\alpha$. Since $\kappa$ is strongly inaccessible, the cumulative level $V_\alpha$ has cardinality less than $\kappa$, and therefore $|a|<\kappa$. Hence the set of ordinals
\begin{align*}
\{\rho(x)+1:x\in a\}
\end{align*}
has cardinality less than $\kappa$ and is contained in $\kappa$. Since $\kappa$ is regular, its supremum is still below $\kappa$. Define
\begin{align*}
\beta:=\sup\{\rho(x)+1:x\in a\}.
\end{align*}
Then $\beta<\kappa$.
Now every $F(x)$ has rank strictly below $\beta$, so every $F(x)$ belongs to $V_\beta$. Therefore
\begin{align*}
B\subset V_\beta.
\end{align*}
This means $B\in V_{\beta+1}$, and because $\beta+1<\kappa$, we get $B\in V_\kappa$. Thus the required replacement image exists inside $M$.[/guided]