the story I'll tell you will help you with the answer.
One year ago, my dad's phone (Galaxy Note 3) had many issues (because the phone was rooted and something messed up the system files). I've tried to flash a stock ROM using Odin (I was sure that the downloaded ROM matched the model and the PDA/AP). After flashing the ROM, everything was working fine except the mobile-related functions. The IMEI has been changed to a generic one (it started with 0049*********) and so the phone wasn't able to connect to the mobile network (no calls, no sms, no mobile internet).
That was even weirdier, because the first time I flashed that phone (to downgrade to Android KitKat), the IMEI remained untouched, but the last time the IMEI was altered.
So, why does flashing a ROM sometimes reset the IMEI?