The code for this can be found in the LoadKnucklesDynPLC routine of the Knuckles in Sonic 2 disassembly. Finally, the fully-converted sprite then is DMA'd from RAM to VRAM.
Instead of DMAing Knuckles' sprites directly from ROM to VRAM, we first run them through a conversion routine which reads each tile from ROM, swaps all the color indices around to fit the Sonic 2 palette, and writes them to RAM.