As far as my understanding goes when you say you are flashing a new custom ROM onto your device you are essentially changing your android version flavor(whatever goes into your
/system partition) and most importantly the kernel(
/boot contains kernel and bootloader).
More on Android Partitions.
Now when you flash a ROM onto your device you generally use a application installed on your machine. Then you enable USB debugging on your device, connect it to your machine and run your application to flash the ROM. First thing here is that the application must recognize the existing ROM/Kernel so that it can replace it with corresponding custom ROM(Eg
CyanogenMod). So your device must be in the list of devices supported by the flashing application. If you have a STOCK ROM than generally all application recognize it and should not be a problem. But if you already have a custom ROM and trying to flash another then it might be a problem.You may wan to read How to Pick the Right ROM for Your Device?
Is it purely because of the bootloader?
As far as CyanogenMod Installer in concerned it does not care if your bootloader is locked or not. It will unlock it for you. Other may require rooted device(How to root your Android device? ).
Or the kernel?
This should not be a problem either because finally it is a Linux kernel on which the android runs(As long as versions are same).
So what is the problem then?
This is my personal understanding. Please correct me if I have mistaken. Kernel is that piece of code that interacts use programs with the device hardware. Now it is very much possible that you have an old device(outdated hardware). Now if you say I am flashing the new ROM that has come to market... it will have a kernel that may require upgraded hardware(Not all things are backward compatible). So even if you flash it on your device some functionality wont wonk. Worst case your phone may get bricked. Hence it is essential to do some research about the ROM you are flashing whether it is compatible with your device.