From axiom of replacement: I have given a set $S$ and have relation $R(x,y)$ such that $x \in S$, then there exist unique $y \in T$ which is image of set $S$ where $T$ is also a set.
But I can use Axiom schema of comprehension where I have $P(y)$ as predicate, then there exist a subset $T \subset S$ such that it consist of exactly those $y \in S $ for which $P(y)$ is true. In symbols I have: $$T = \{y\in S|P(y)\}$$ Then it says that axiom schema of comprehension is a consequence of axiom of replacement as:
$\bullet\,$ $\,\lnot(\exists y\in S : P(y))$ then define $T = \phi$
$\bullet\,$ $\, \exists \,\hat{y}\in S : P(y)$ then by definition I have $$\text{when } P(x) \text{ is true, then } R(x)=y$$ $$\text{when } P(x) \text{ is false, then } R(\hat{y})=y$$ From all of this $T$ is image is image of set $S$ under relation $R(x,y)$
My confusion is:
$ \color{red}{\text{ how }y\in S \text{ and axiom schema of comprehension is a consequence of axiom of replacement}}$ Please provide me one example also. Thanks in advance!
note: I searched on internet and it didn't help and I am physics person and started learning set theory.
Long comment
See Relation to the axiom schema of replacement for the derivation of Separation from Replacement.
Please, note that in the Axiom Schema of Replacement we use a formula $\varphi$ that is functional (which relates each set $x$ to a unique set $y$) and not a relation $R$ (i.e. a set).
For a relation $R$, i.e. a subset of $S \times T$, we have the domain $S$ and the codomain $T$. We define the range (or: image) of $R$ as the subset of the codomain:
Thus, by definition: $\text{Ran}(R) \subseteq T$.