I have Asus Maximus X Code mobo and G.Skill Trident 16 GB RAM model F4-4133C19D-16GTZKW. Now the CPU is 8700K. I am thinking about upgrade to 9900K.
8700K seems to be Dual Channel PC4-21300U (DDR4-2666) and
9900K seems also to be Dual Channel PC4-21300U (DDR4-2666).
Mobo is ok for that CPU, but would I need to change RAM?
You need to use the memory config supported by ASUS for that motherboard.
If you do upgrade the processor, make sure you upgrade the ASUS bios before installing the new processor.
Technically, your memory (which is DDR4-4000) is out of spec. for BOTH of these processors. These processors are validated for DDR4-2666 memory. Any speeds above that are overclocking the processor's memory buses. Operation is not guaranteed at these overclocked speeds. As Al said, the ability to run at these speeds is more often gated by the design and implementation of the motherboard and its BIOS than anything else.
Asus documentation - qualified vendor list - shows that this memory is supported and it is working flawlessly. I would be stupid to use slower memory for such a great set of elements.
I have no problems with that memory and I will think more about upgrading to 9900K when the prices will drop down a little.