Well, itdoesn't"end up with 2 lambda*x transpose*a equal to zero"! It ends up with mplusthat equal to 0.

As to where the "2" came from, it is essentially from differentiating a square. Or you might prefer to think of it as using the product rule.

Your Lagrangian is . Differentiating , with respect to x, gives and, since , that is the same as .