Squaring is not an injective operation so why is it allowed? I do have a problem with squaring, lots of students do it escpecially when they have to solve things like $\sqrt x$  but i do not why. This maybe a dumb example but lets assume $-2=2 $ if I $(..)^2$ i would have $4=4$ which would be no contradiction 
 A: The fact that an operation isn't injective is good reason to be careful when using it, but there's no need to avoid it altogether.
As a simple example, let's solve $$\sqrt x = x-1$$
Squaring (non-injective) we see that any solution would satisfy $$x=x^2-2x+1\quad \implies\quad x^2-3x+1=0$$
Thus our solution(s) must be among $$\frac {3\pm \sqrt 5}2$$
Checking those shows that $x=\frac {3+ \sqrt 5}2$ solves the problem we were interested in while $\frac {3- \sqrt 5}2$ does not. That value is a solution to the similar equation $$-\sqrt x=x-1$$  Of course, squaring removed the difference between these two equations.  
Thus, squaring the original equation quickly led to a solution, but we had to take care to remove an extraneous "solution" generated in the process.
A: Your example is not as dumb as you suggest; it is a nice example of the principle of explosion, which states that from a contradiction you can derive whatever you like (hence its Latin name, ex falso sequitur quodlibet).
Put more formally, if $p$ and $q$ are propositions and $p$ is false, then the implication $p \Rightarrow q$ is true regardless of whether $q$ is true or false.
This means that if you make a false assumption $p$, such as the assumption that $-2=2$, then you can derive both true consequences (such as $4=4$, obtained by squaring both sides) and false consequences (such as $0=4$, obtained by adding $2$ to both sides).
This is also a nice illustration that you cannot prove that a proposition $p$ is true by assuming that it is true and deriving something else that is true—this is a common error amongst beginners at mathematical proof.
This arises a lot in solving equations, since you assume the equation holds and derive its solutions—this says that if such-and-such equation has a solution $x$, then $x = $ this, that or the other. But this does not prove that if $x=$ this, that or the other, then $x$ is a solution to the equation. Plugging the $x$es back in and verifying the equation holds (or doesn't) is what gives you the converse implication. This is illustrated in lulu's answer.
A: Note that in generally accepted notation we have that:
$$\sqrt {m^2}=|m|$$
I'll take lulu's answer as an example to demonstrate this. First we have:
$$\sqrt x=x-1$$
We square to get:
$$x=(x-1)^2$$
But if we now square root again, we have:
$$\sqrt x =|x-1|$$
Note that $$|x-1| =
\begin{cases}
x-1,  & x\ge1 \\
1-x, & x<1
\end{cases}$$ and we note that any solutions to $x=(x-1)^2$ with $x<1$ do not count to our equation. 
The solution lulu excluded was $\frac{3-\sqrt5}{2}\approx 0.38$ and so we see why it doesn't fit.
So while squaring brings in fake solutions, they are easy to spot and remove.
A: $\require{cancel}$Strictly speaking, you are correct that the lack of infectivity of the $(\cdot)^2 : \mathbb{R} \to \mathbb{R} $ function means that it can't be used for the style of proof commonly found in problem sets where you write a sequence of equalities until you get a trivial one. Functions like $(\cdot)^2$ are potentially usable if you have other knowledge about their arguments. For instance, if the argument is non-positive or non-negative, $(\cdot)^2$ is injective.
If you have an equation involving an unknown, then applying an injective function to both sides will not introduce any spurious solutions.
$$ x + 7 = -2 \tag{1} $$
applying $- 7$ to both sides gives us:
$$ x = -5 \tag{2} $$
Equivalently, if we start out with an $\ne$ inequality, an injective function $(+5)$ will preserve the truth of that statement.
$$ 2 \ne 4 \tag{3} $$
$$ 7 \ne 9 \tag{4} $$
However, if we apply a non-injective function such as $f(z)=z^2$, inequalities are not necessarily preserved.
$$ -2 \ne 2 \tag{5} $$
$$ \xcancel{4 \ne 4} \tag{6} $$
This is perhaps easiest to see if we apply the constantly zero function $0$ to both sides.
$$ 7 \ne 302 \tag{7} $$
$$ \xcancel{0 \ne 0} \tag{8} $$
