If you expand (x+a)(x+b), you get x\^2 + (a+b)x + ab. That means that, if you want to factor x\^2 + Tx + S into (x+a)(x+b) say, then you want to find numbers a,b such that a +b = T and ab = S. This is because if you want (x+a)(x+b) = x\^2 + Tx + S, then x\^2 + (a+b)x + ab = x\^2 + Tx + S. When two polynomials are equal, their coefficients in each degree must agree. Thus, T = a + b, and S = ab.
​
In your case, (-5) + (-2) = -7, and (-5)(-2) = 10, so x\^2 - 7x + 10 = (x-5)(x-2).