Assuming your items are set up right and the account types are correct for each account field on the inventory items, then...
This happens when you have oversold an inventory item below a 0 Qty balance and then subsequently purchase more of the item, but for a price above or below the average cost.
The GOGS you'll see as a result of the purchase in this case is an adjustment for the difference between the estimated GOGS added to the sale when the Qty went negative and the actual GOGS that are later a result of the purchase for a different price.
This is basic stuff that QB has done since it had inventory, which I think was added in 1998 (if I remember correctly.) Not sure why Intuit doesn't seem aware of it.