Will Security apps work even after flashing new rom? Assume that I have turned on Android Device manager to locate my phone in case of theft,  and I also installed some security apps which can send message when someone tries to change the SIM card. 

Now suppose I lost my phone. The one who finds it is tech savvy. Firstly, (s)he does a factory reset after booting into Recovery mode, followed by flashing a new custom ROM, and then (s)he starts using my phone.

Will Android Device Manager still  work?
The Android Device Manager will probably still work, provided the new ROM contains the GApps. But it won't listen to you any longer.

If, as you describe in your question, the "new holder" is from the tech field, and did a thorough wipe plus installs a new ROM, nothing from your installation survives. It simply can't, with really all storage wiped/overwritten.

What some of those security apps offer is to be integrated with the ROM (on rooted devices only, of course). That helps to survice a factory-reset, as that doesn't touch the ROM (or, more precisely: /system, where those apps are installed then). But with the entire ROM and recovery replaced, plus all data wiped, where should they "stay"?