Serial Number Got Changed After Factory Reset After "Factory Resetting" my tablet I realized that the serial Number was changed (it is now a weird number 0123456789ABCDEF). 

Edit March 17 2019

This is the number that shows when I do adb devices. As far as I know this is the serial number and not the Android ID.

End Edit

Why did this happen?
How do I go about returning it to its original SN?
How do I prevent it from happening again?

I have seen some options of changing the SN number but I'm reluctant to try them since the programs they use doesn't look like official (safe) programs.
Your serial # is provided by the Linux Gadget driver. Depending on your kernel version it's either in

/config/usb_gadget/g1/strings/0x40*/serialnumber
or

/sys/class/android_usb/android0/iSerial


Since you're rooted, you can easily change the number by writing to this &quot;file&quot; - which is really just a parameter that the driver will digest and export accordingly.
While you're at it, there are other cool strings there, like Manufacturer and Product , which you can mess with, and similar &quot;files&quot; containing USB identification, and controlling the device persona (Mass storage, MTP, PTP, etc)