If two transactions are sent into the network using the same private key and the same funds but sent to different bitcoin addresses – then as the transaction propagates through the network one half of the network will accept one transaction and the other half, another.
The situation is resolved by which side of the network resolves one of the two transactions into a block first.
So if you try and spend your bitcoins twice – once to a merchant and once back to another address under your control, then you will have a 50% chance roughly of regaining your money and getting the product for free if chance favours your address as being the bitcoin networks consensus .
This does depend though on which transaction gets propagated further into the network. For example if transaction A reaches ten mining nodes controlling 80% of the network hashing power first and the other transaction only reaches 20%, then transaction A will have an 80% chance of being included in the next block and be the confirmed transaction.
There are ways of safeguarding against this – whereby wallet operators keep strong links into mining nodes to propagate their transactions fed directly in – so another transaction spending the same output can’t be fed into the network on a fraudulent basis.