Can we flash any Android version which suits a particular kernel in any Android

Since we mostly talk about compatibility of any ROM with its kernel and as any ROM decide what android version we are using so can we do flash a kernel and corresponding compatible ROM to any old Android phone so that we can change it’s Android version