I think this really comes down to how much you want to spend in upgrades. Like TMC said, the 9900K can be swapped in without changing anything else for about $250 or the 7700K for about $150. A switch to a newer generation of intel CPU would require a new motherboard as well (intel doesnt play nice with chipsets in this regard 😆). A switch to AMD could be done on the budget side of things with an AM4 socket chip and motherboard. I assume youre using DDR4 ram that could also be used in the AMD system. Something like a 5800X3D (8core $350), 5800X (8core $250), or 5600X (6core $150) could be paired with a B550 motherboard (~$100). Or you could go wild and update to the latest generation Intel or AMD, but that would require purchasing RAM and likely a cooling system as well. I personally like the upgradability of the AM5 socket, but I built my PC before the RAM and SSD prices went through the roof so that may have changed my decision making when I upgraded. I'm no Intel expert, so maybe someone a bit more familiar with that side of things can chime in.
EDIT: Another thing to consider is what games you are looking to play after the upgrade. If you are looking to play newer AAA games, even upgrading to the latest and greatest AMD or Intel CPU may not be enough if your GPU is a few generations old.