I solved a trigonometric equation and got the following solutions: $$x=\frac{\pi}{6}+2\pi n$$ $$x=\frac{5\pi}{6}+2\pi n$$ $$x=-\frac{\pi}{2}+2\pi n$$
For all integer $n$.
Is it valid to write the solution like that?
$$x \in \{ n\in \mathbb{Z} \ | \ (x=\frac{\pi}{6}+2\pi n \ \cup x=\frac{5\pi}{6}+2\pi n \ \cup x=-\frac{\pi}{2}+2\pi n)\}$$
No. Those $\cup$ signs make no sense and you are asserting that your set of solutions is a subset of $\mathbb Z$.
You can write your set as$$\left\{\frac\pi6+2\pi n\,\middle|\,n\in\mathbb Z\right\}\cup\left\{\frac{5\pi}6+2\pi n\,\middle|\,n\in\mathbb Z\right\}\cup\left\{-\frac\pi2+2\pi n\,\middle|\,n\in\mathbb Z\right\}.$$