Kernel Panic when booting into Mac OS. iMac 27 2017
First you should try removing any third-party, external peripherals you have connected to your iMac. If the problem persists, and your observations are correct, then you have a hardware error with your iMac. You should contact Apple or the dealer for repairs. You can also use the built-in hardware test to search for errors, but be aware that it only catches a small subset of possible errors.

The reason I say this is that when you boot into Internet Recovery, it is not using any information from your macOS installation or from your hard drive in general. If that kernel panics during boot, you have a hardware problem.

There are many possible reasons as to why this seems to only affect macOS and not Windows in Bootcamp. You could be lucky that you're not hitting the faulty hardware, and it could be that Windows in general does not use that portion of the hardware - or that flaws in that piece of hardware is inconsequential for Windows (or at least you haven't noticed the problem yet).

The actual defective hardware could be many things, but it is often faulty RAM or similar component. The hard drive is not used for Internet Recovery, but there's a small chance that a defective hard drive could interfere anyways - however, in that case you shouldn't be able to run Windows from the same drive.