The 21.5-inch iMac unofficially supports up to Intel Core i9 processors; surpasses the 24-inch iMac with an Apple M1 SoC
Luke Miani has documented that it is possible to get an old 21.5-inch iMac running using a processor that Apple never offered for it. Officially, Apple offered up to the Core i7-8700, although Miani bought the base model with a Core i3-8100. Both processors rely on the LGA-1151 socket, meaning that the iMac is upgradable beyond the Core i7-8700.
The LGA-1151 in the 21.5-inch iMac is bound by a 65 W TDP limit, mind you, ruling out any K or KF processors, along with the Core i9-9900KS. However, the Core i9-9900 (Amazon affiliate link) is eligible, which Miani chose for his build.
Miani sells his upgraded 21.5-inch iMac as being more powerful than the new M1 model, as the video below shows. The upgrade process is a long one though, and is fraught with risks not only to components but to your health.
Ultimately, we would only recommend upgrading a 21.5-inch iMac to the Core i9-9900 if you know what you are doing beforehand. Nonetheless, Miani has shown what performance the 21.5-inch iMac could have offered, even if it can only maintain the Core i9-9900 at its 3.1 GHz base clock.