It's been a number of years since I built a custom kernel, but you might get the option to disable TCP/IP in the configuration menu.
If you have the kernel sources, try running:
That will present you with a bunch of different options for building the kernel. I think there is an option to disable the tcp/ip stack in there.
How you'd go about replacing it with your own - I couldn't say. I primarily develop user-space applications. I haven't had much time or inclination to mess around at the kernel level.
The sources will probably help you to work it out.
If nothing else - assuming that the menuconfig script
does offer you the ability to disable TCP/IP - you can take a look at the menuconfig script and the rest of the build-system to work out which modules are disabled/excluded from the build when you select the option to disable TCP/IP and then take a look at those modules to see how they have been implemented.
Then I guess you'd need to add your own module and amend the build-scripts to include it in the build.
Again, I haven't dealt with a lot of kernel level stuff, so I don't know for sure.
The official documentation for the kernel might be of some use:
https://www.kernel.org/doc/html/latest/index.html