Below is the proof of : Prove that for any two ideals $A$ and $B$ of ring $R$,$A+B=\langle A \cup B~\rangle$ .
Proof:
By theorem (for any two ideals of a ring $R$ ,then the set $A+B$ is an ideal of $R$) such that ,$A \subseteq A+B$ and $B \subseteq A+B$ , so $A\cup B \subseteq A+B.$
Let $X$ be any ideal of $R$ such that $A\cup B \subseteq X.$ If $z \in A+B$ then $z = a+b$, $a \in A$,$b \in B$. Now $a \in A\cup B~~$,$~~b \in A\cup B \implies a,b \in X \implies z \in X.$
Hence,$A+B \subseteq X$.Consequently ,by definition $A+B=\langle A \cup B \rangle$
The thing I can't understand is where did we use the fact that $X$ is an ideal.Won't the proof work if $X$ is just a subset of $R$ such that $A\cup B \subseteq X.$?
You concluded that $a,b \in X$, and therefore $z = a+b \in X$. This would not be true if $X$ were an arbitrary subset.
For instance, in $\Bbb Z$, look at the ideals $(2)$ and $(3)$. $(2) + (3) = \Bbb Z$, but we could take $X = (2) \cup (3)$, which is not an ideal and does not contain $(2) + (3)$ (in particular, $1 = 3 - 2 \not\in X$.
The proof you gave did, however, show that this holds whenever $A$ and $B$ are ideals, and $X$ is any additive subgroup containing $A$ and $B$ (ie scaling didn't come into play).