We say that a set $X$ is transitive if it is contained into the corresponding power set $\mathscr P(X)$.
Now for $\textbf{any}$ set $X$ let's we put $$ S(X):=X\cup\{X\} $$
So if $y$ is in $\bigcup S(X)$ then there exists $Y$ in $S(X)$ such that $y$ is in $Y$ but if $Y$ is in $S(X)$ then it is in $\{X\}$ or in $X$ so that in the first case $y$ is in $X$ whereas in the second it ($y$) is in $X$ provided $X$ is transitive and thus if $X$ is trivially contained into $S(X)$ then into the transitive case we conclude that the equality $$ \bigcup S(X)=X \tag{1} \label{1} $$ holds. Now my text book into an exercise (clik here to see it) ask to prove (apparently) that eq. \eqref{1} holds generally but unfortunately I was not able to prove so that I put here a specific question where I ask to prove or disprove if \eqref{1} holds generally. Could someone help me, please?
Your concern is correct: the result holds for transitive sets, i.e. sets such that if $x∈A∈X$, then $x∈X$.
For some counterexamples, see Enderton's Set Theory, page 72: consider the set $\{ 0,1,5 \}$.
We have that $4∈5∈ \{ 0,1,5 \}$ but $4∉ \{ 0,1,5 \}$.