Can I remove old discount codes without affecting contribution records?
I tested deleting a discount code with CiviCRM 5.2.1 and CiviDiscount 3.4

When deleting a discount code I saw this warning:

WARNING: Deleting this discount code (GMC610) will prevent users who have this code to avail of this discount. Do you want to continue?

After I deleted the code I searched for the contact id in the "cividiscount_track" table and the item was still there. However, it appears the code was removed from the "cividiscount_item" table as would be expected. So, it appears the code is removed from the list but the tracking data remains in the database.

I checked the Contributions in the contact record of the contributor before and after and I did not notice any changes.

It looks like the only thing that is removed in the contact record is on the 'Codes Redeemed' tab, you will no longer see the code in the CODE column. However you do see the date so you will know some type of code was redeemed.

In summary, it seems safe to delete discount codes as long as you don't mind losing the record of which code was used by a contact.