Can someone explain why product-sum factoring works?

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.

&#x200B;

In your case, (-5) + (-2) = -7, and (-5)(-2) = 10, so x\^2 - 7x + 10 = (x-5)(x-2).
Going the other way you can multiply out to get:

(x + a)(x + b) = x^(2) + bx + ax + ab

= x^(2) + (a+b)x + ab
If you like, you can always literally reverse the process like so:

x^(2) \- 7x + 10
= x^(2) \- 5x -2x + 5\*2
= x\*x + (-5)x + (-2)x + (-5)(-2)
= x(x - 5) + (-2)(x - 5)
= (x - 2)(x - 5)

where the final step was done by noticing the common factor of (x - 5). The hard part about doing this is spotting that -5 and -2 are the required numbers, and of course if you can do that, there's no need to write out the whole factorisation process, you just skip to writing it in factored form as normal.
by
Example:

Pair of numbers
↓        ↓
(x +3) · (x -5)         |Expand parentheses
= x² +3x  -5x -15         |Combine like terms
= x²   -2x    -15
↑       ↑