I guess kernel panic occured due to one of the following reasons or may be more
1 . Compiling the kernel is basically installing the kernel so instead of replacing the old kernel it instead got stuck in deadlock where neither of the kernels were able to use the memory thus the panic.
The new kernel entered into some kind of loop, think it this way "it tried to call itself" or simply it became a type of fork bomb thus the out of memory error and panic.
The partition allocated for the new kernel was not sufficent. Try to make a different partition,mount it,sys link it so that others programs can execute it. Now re compile it using gcc and chains(linker)
Instead of replacing the kernel it killed itself.
If you extract a kernel tarball which is initially 300 mb of size, after extracting i.e "tar -xvf kernel.zip" it becomes a giant of 900 mb of size. After installation of packages like gcc,g++,gnu-make,etc and compiling it, the compiled kernel may become a mamoth of 2 GB of space. So If it the partition doesnt have that much space out of memory may occur.
You didnt provide a swap area. As building a kernel is resource intensive it needs both a good amount of space,a swap are and ram.
During installation it creates sub folder like /mount, /proc, /boot ,/dev etc . So that each part gets respective location which some how failed due to out of memory.
Usually a kernel is compiled in chroot like enviroment, but if the chroot is not properly set it may fail to get a resource like proc,mnt,dev thus the panic.
If you still need some help then checkout these two places #1 kernel team for ubuntu , #2 kernel debugging team for ubuntu
As your update seems to implying compiling the kernel worked.
It could only mean that you compiled the whole kernel.
Usually a kernel has everthing in it which may be important to one but a waste of space and time for other.
So either you could use the new kernels from ubuntu kernel . In my case its v4.14-rc1.Download the kernel which match your arch.
I have x86_64 so I would choose 64 bits one.
I would download these
and would then issue "sudo dpkg -i *.deb" to compile all.
Now it seems that the kernel you compiled are of more than 1GB thus its using more resources.
The ubuntu kernel has many parts stripped out so its low i size and uses heavy compression.
Your kernel might have everything in it and can be used by IOT,servers,desktop, and may be compatible with arm 64,amd64, etc as it may have all the modules present to run these.
So to reduce it you need to remove all the parts useless in your case like drivers for hardware you never have heard of. Stripping server parts where ever possible.
Great work by the way as kernel compiling is a headache as its uses intensive resource ,time and patience
As you mentioned that your initrd.img file was huge. Could you atleast post a screenshot of your /boot/ or in terminal use "ls -l " to list the size of everything.
Kernel happens to be the heart of any Linux distro. Its very complex so without knowing anything one can just guess whats the issue.
I would still suggest you to strips the unwanted modules from your kernel and then compile it.