why can't we format bootloader code Some phones had locked bootloader.  As far i understand bootloader is a piece of code responsible to load the os. but that is still in the harddisk right? 
so why can't we delete that code and put our own.
First, the definition of a bootloader (as described by Technopedia):


  A boot loader primarily manages and executes the boot sequence of a
  computer system. A boot loader program is typically started after the
  computer have finished performing the initial power. It fetches the OS
  kernel from the hard disk or any specified boot device within the boot
  sequence, into the main memory. A boot loader is associated with only
  a single operating system. An operating system can also have multiple
  boot loader programs classified as primary and secondary boot loaders,
  where a secondary boot loader might be larger and more capable than
  the primary boot loader.


On samsung devices you can enter into download mode and plug your phone into a pc and open up Samsung Odin 3 and flash a bootloader by selecting BL and the file

Also flashing bootloaders is EXTREAMLY RISKY. Flashing the worng or incompatable bootloader is worst than flasing a boot.img that wasnt meant for your device. It will result in A hard brick and its very rare to recover from that unless you have a Programmer JIG/JTAG

Also flashing items in a locked bootloader is very dangerous because theres 100% cHance of Bricking your device if you flash a custom item..

And a bootloader is programmed into a ROM chip it cannot be easily changed fomating. Its better for you to not interfare with your bootloader unless you want to unlock it and root or flash things to your device.. Custom roms are made with these 2 CRITICAL IMGs BOOT.IMG SYSTEM.IMG

Also theres no need to make a custom bootloader because almost every device has the same bootloader type but differ from code and compatibility