This is normal.
If you sell inventory so that you end up with a negative QOH, QuickBooks estimates the COGS on the sale based on the last known average cost for the item (or FIFO cost of you're using FIFO).
If you then purchase more of the item at a later date using a price that is different than that estimated cost, QuickBooks adjusts it on the purchase, adding or subtracting COGS on that transaction.
But, if you enter a purchase on an earlier date than the sale, or you edit the purchase and change the date to be an earlier date, then QuickBooks does not enter a COGS adjustment on the purchase and instead recalculates the COGS on the sale.
-------------------
Note that, actually, none of the COGS line items you see in reports - those automatically calculated when you record sales for inventory items (and sometimes purchases) - actually exist in your data file. Instead they are manufactured at report time based on each item's history of purchases and sales, in date order. So, when you enter data out of order, or you change the dates of existing transactions, the results you see in reports will re-calculate and potentially change.
For example, if you purchase a brand new inventory item (with no history) for $10 and then sell it a week later for $20, your COGS will appear as $10 on the invoice in reports. But, then if you purchase another of those things for $15 and date that purchase before the invoice, the COGS you see on reports for the sale will change to $12.50.