The idea is that, by default, we should assume the payment is a gift, unless we have specific evidence to suggest that it is offered in exchange for something.
In the first case, the father-in-law has given no indication as to why he is giving her the money. It could be that he is indifferent to whether she remarries or not, and simply wants her to have a steady income in either case. He may be presuming that, if she remarries, her new husband will be able to provide for her, but until such time, he (the father-in-law) will pay her way. We certainly do not have evidence to show that he actually wants her to stay unmarried and is paying her for that purpose.
In the second case, the father-in-law has given us more evidence. His words make it explicit that he does want her not to remarry, and that he is paying her in order to get her not to. Since he is clearly paying money with the intention of getting another party to do something (or in this case, to refrain from doing something), we understand it as a contract.