Currently I am reading Simpson's Subsystem of Second Order Arithmetic, Chapter II.3, Primitive Recursion.
Notations: $(i,j) = (i+j)^2+i$
Theorem II.$3.2$ The following is provable in RCA$_0.$ If $f:X\to Y$ and $g:Y\to Z$ then there exists $h=gf:X\to Z$ defined by $h(i) = g(f(i)).$
In the proof, the author introduced the following formula $$\exists j((i,j)\in f \wedge (j,k)\in g)\leftrightarrow (i\in X\wedge \forall j((i,j)\in f\rightarrow (j,k)\in g)).$$ Then he quoted by $\Delta_1^0$ comprehension that $h$ exists such that $$(i,k)\in h \leftrightarrow \exists j((i,j)\in f \wedge (j,k)\in g).$$
I fail to understand why is the formula $\Delta_1^0.$
I have a vague feeling that left hand side is $\Sigma_1^0$ while the other side is $\Pi_1^0$. However, on the right side, the quantifier is inside the formula, not at outside. Would this affect the formula?
Yes, this is still $\Pi^0_1$ - we can just move the quantifier over (as Wojowu points out in their comment): $\varphi(x)\wedge\forall y(\psi(x,y))$ is equivalent to $\forall y(\varphi(x)\wedge\psi(x,y))$.
More complicated simplifications are possible as well - for example, we have $$\mbox{"$\Pi^0_2\wedge\Sigma^0_1=\Pi^0_2$,"}$$ which is to say, the conjunction of a $\Pi^0_2$ formula and a $\Sigma^0_1$ formula is (logically equivalent to) a $\Pi^0_2$ formula. In general, we have the following rule: if $\varphi$ is $\Pi^0_m$ or $\Sigma^0_m$, $\psi$ is $\Pi^0_n$ or $\Sigma^0_n$, and $m<n$, then $\varphi\wedge\psi$ and $\varphi\vee\psi$ are each (logically equivalent to) a formula in the same complexity class as $\psi$. The more complicated class absorbs the simpler class.
We do have to be careful, however, since the arithmetical classes are only partially ordered in terms of complexity: for example, if $\varphi$ is $\Sigma^0_1$ and $\psi$ is $\Pi^0_1$, $\varphi\wedge\psi$ need not be equivalent to either a $\Sigma^0_1$ or a $\Pi^0_1$ formula.
If you're familiar with computability theory, it may help to think of things in those terms: e.g. the intersection of a computable set and a co-r.e. set is co-r.e. The arithmetical hierarchy in syntax is extremely closely related to the arithmetical hierarchy in computability: the sets of natural numbers which are $\Sigma^0_n$ (resp. $\Pi^0_n$) in the computability-theoretic sense are exactly those which are definable by a $\Sigma^0_n$ (resp. $\Pi^0_n$) formula in $(\mathbb{N};+,\times)$.