For Sam to not know the numbers there must be multiple ways to get that sum. And for Pete to know that Sam didn't know the answer and not to know the answer himself the product of the 2 numbers must have multiple solutions.
Both of this happens if we take the numbers as 3 & 4.
Sum = 7
Possibilities => (2 + 5), (3 + 4).
Product = 12
Possibilities ========>(2 * 6), (3 * 4)
Corresponding sums.........II..........II
............................................8..........7.
Now Sam can eliminate (2 + 5) option because the corresponding product 10 has only this possibility so Pete would have known the answer in that case.
So he can declare the numbers as 3 and 4.