I believe that Funygirl is correct although I'm not sure that it is a 'law' as such, just more of a convention.
An 'engagement' used to be seen as a contract and one demonstrated to family and friends, and therefore the ring was a physical token to represent the intent of both parties to be bound by this 'contract' to marry.
Should the engagement end, by whichever party, the contract was broken and therefore the ring was to be returned, again as a physical demonstration of the end of this contract to marry.