Oh you foolish wannabe minecraft veteran, isnt that obvious?
Say for example you want to sell the player sharpness II sword which can be upgraded to sharpness V in a second trade.
Obviously you put something like Enchantments:[{id:sharpness,lvl:2}] in there. And as everyone knows; repairing that sold item changes the NBT to Enchantments[{id:"minecraft:sharpness",lvl:2s}]
Iam not even kidding. The quotes are important, the minecraft: is added and the level changes from "2" to "2s"
Changing these tags on the sold item in the first place and changing it in the buy on the second trade finally made it work.
But wait, what about Item.tag.RepairCost you ask? It surely changes! Yes it does and the game doesnt even care, you can make the trade but: (and thats also a cool feature) you can no longer SHIFT-click the trade to quickstack the needed item into the trading slots. You gotta do that oldschool style click+drop.
Iam at version 1.18 as of now. Gonna test this for 1.17 later.
And yes i insulted myself a bit at the beginning of this text, but im cool with that.