For commodities that are only purchased on buyout (gems, crafting materials, blacksmith recipes), the price displayed is just the highest amount you will pay for it. In most cases, you get some amount of refund, this could be because:
- Someone else offered it for lower: As @Novarg pointed out, this is probably what happened in your case.
- The order was split into different lots: If you buy 100 Fallen Tooth for 50 gold each (acc. to UI), but maybe there is someone selling 23 @ 35g, another person selling 50 @41g etc. ... then Blizzard automatically splits your order and buys the lowest priced ones first, and then refunds the difference.
Also, I'm not sure if the purchase price displayed is the actual current price or some sort of moving average (or just a heavily cached version that is updated rarely). It seems to give you refunds way too often to be entirely attributable to reason #1.