It is best practice to re-install Windows when switching out motherboards. That way you start fresh with drivers and get rid of any motherboard specific software that might cause a problem with a new board.
You may be able to get away with swapping the motherboard and CPU. Intel hasn't changed too much between 6th and 8th gen and the OS should have chipset drivers to get you started. Then you would just have to install the latest drivers from the motherboard manufacturer's website. You could also pre-emptively uninstall all motherboard drivers and then shut down the computer, swap the parts, and turn it back on.
If you are going to attempt that, you should back up the whole drive with an imaging tool like Macrium Reflect. You will need another drive roughly the size of your current one to do this.
If you are wondering why an i5-6500 is more expensive than an i5-8400, they don't make either anymore. So the prices are whatever is left and are available for people to upgrade older machines or replace failed parts. Though Intel chips for retail sale tend to stick around their release price. Second number there is important, 5 is bigger than 4, so effectively the 6500 was a more expensive chip to begin with. i5-8400 is just newer and faster compared to it. So despite being cheaper is faster.
Late model i3 are faster than both of them, and cheaper still.