In this scenario, neither address A nor address B had a sufficient balance to pay 0.5 BTC by itself. The two together did have enough. So, the clients are intelligent enough combine the amounts of two addresses together in order to meet the desired transaction amount.
Unfortunately, the combination has the effect of sending bitcoins to yourself as “change” in the transaction. In this scenario, all of the available balance was split between address A and address B. In combining those in order to satisfy the payment to C, some was consolidated as “change” into address B.
Think of it mathematically, as well. This shows the equilibrium, from the point of view of the accounts you control.
balance(A) + balance(B) = payment_to(B) + payment_to(C) + transaction_fee(0.0005)
This is the transaction.
balance(A) + balance(B) - payment_to(C) - transaction_fee(0.0005) = payment_to(B)
That payment_to(B)
is the change.
Unfortunately, because of the number of confirmations the clients wait before allowing one to spend incoming transactions, the balance is present but unavailable to spend for several minutes, or as much as hour or more.
Clients should handle this better by warning if transaction about to be sent will create this confusing situation.