In set theory, a function $f:A \to B$ is defined as a subset $f \subseteq A \times B$ such that $$\forall x \in A(\exists!y \in B((x,y)\in f)).$$ Consider the example $f:\mathbf{R} \to \mathbf{R}, x \mapsto 2x^2+3$ which is just an arbitrarily chosen example. To show that this is a function, one has to show that $f$ defines a set that satisfies the property above. As far as I know, sets in set theory are always of the form $$\{a \ | \ \text{some property of a}\}.$$ Hence I think one can write $f$ as $$\{z \ | \ \exists x(\exists y(x \in \mathbf{R} \wedge y \in \mathbf{R} \wedge y=2x^2+3 \wedge z=(x,y)))\}$$ is this correct? Could one also express this as $$\{z \ | \ \exists x(x \in \mathbf{R}) \wedge \exists y(y \in \mathbf{R} \wedge y=2x^2+3) \wedge z=(x,y)\}?$$ If this is the case, I should not be able to write it as a set by "commuting" the introduction of $x$ and $y$, since $y$ depends on $x$, right? What I mean by that can be seen here: $$\{z \ | \ \exists y(y \in \mathbf{R} \wedge y=2x^2+3) \wedge \exists x(x \in \mathbf{R}) \wedge z=(x,y)\}?$$ Since $y$ depends on $x$ it seems weird to me if this would be possible.
Since I try to formalize things in my spare time (I am just starting) I wondered how the statement $$\forall x \in X \forall y \in Y \forall z \in Y(((x,y) \in R \wedge (x,z) \in R) \implies y=z)$$ can be formalized, where $X,Y$ denote some sets and $R \subseteq X \times Y$ denotes a relation. I know that well formed formulas allow for the part "$\forall x \in X \forall y \in Y \forall z \in Y$" followed by a formula. However, I am not sure how to express an according formula. This statement can be found in https://en.wikipedia.org/wiki/Function_(mathematics).
Not a complete answer.
Firstly, it is not generally true that $\{ a \mid \text{some property of } a \}$ is a set: what if the property is $a \not\in a$? If then $b = \{ a \mid a \not\in a \}$ then is $b \in b$ true? This is called Russell’s paradox. What is true (in some axiomatisations of set theory, for instance ZF) is that if $c$ is a set then $\{ a \in c \mid \text{some property of } a \}$ is a set (this is called the axiom of separation, or comprehension).
Your first formalisation of the set describing the function $f \colon x \mapsto 2x^2 + 3$ is correct; the second one is not. The quantifier $\exists x$ only binds instances of $x$ in the next “rank” of the formula: $\exists x (\varphi(x))$ is fine, but $\exists x(\varphi(x)) \land \psi(x)$ is not; the instance of $x$ in $\psi(x)$ is free, i.e. not bound. In fact, since variables can be relabelled, the formulas $$\exists x(\varphi(x)) \land \psi(x)$$ and $$\exists x(\varphi(x)) \land \psi(t)$$ are logically equivalent.
I am not certain what you mean by “formalising” that last statement; it is, after all, already expressed in the formal language. I’ll update this once OP clarifies.