While you can connect via USB-C an external GPU unit (eGPU) in the Intel systems, I'm not sure if you can with the M1 or M2 systems. There is also the issue of which display you are driving. Driving your internal display steals away needed bandwidth for the eGPU, instead you'll want to connect an external display.
Reference: Use an external graphics processor with your Mac
I do wonder if an eGPU is that useful with the 24" iMac, part of the issue is within the M1 SoC as its has some limitations with its TB ports. You'll need to speak with the different vendors listed in the guide I posted above.