Recolouring a texture using Materials

I have 3 textures:

Using a material, I want to recolour the hockey players to use the colours in the 3rd image. I have the logic for a render target (RT) but it performs poorly. I essentially read each pixel from the first image in a RT and find it in a table with all the values in the 2nd image. The “position” is then recorded, and I read the colour from the 3rd image and apply it to the pixel in the 1st image.

How can I do this in a material?