It's not just that - these deals don't happen on a whim. Deals like this take weeks, if not months, of negotiations. This deal has been happening in the background while Motorola has continued to deliver a new phone (the G), and provide KitKat updates to three different brands before any other non-Google phone brand received them.
This has been covered elsewhere, but the $12.5 billion is not a hard number. Motorola came with $3 billion in cash assets and $1 billion ix tax credits, so the initial sale was really $8.5 billion. Google sold the old Motorola Solutions set-top box part of Motorola for $2.4 billion shortly after the sale. With the $2.9 billion sale of Motorola Mobility, that's a loss of $3.2 billion (plus about $1 to $1.5 billion in losses in the 2 years that Google owned the business.)
But, that last part in parentheses is probably the real reason. Why should Google throw away hundreds of millions of dollars of profit a year when that's not their primary business? I think the key to this deal was the announcement the day earlier that Google and Samsung entered into a patent licensing deal that includes Samsung's promise to develop a more close-to-stock version of Android for their devices without replacement apps for Google services.