To make your code a bit more bulletproof, change your entity declares to this
ENTITY* mangyanenemy = NULL; or ENTITY* mangyanenemy = 0;
PANEL* pan_backselectenemy = NULL; or PANEL* pan_backselectenemy = 0;
Now you can test if the entity is in use or not.
To see this test in action, and to possibly fix your problem, change the following too.
function func_backselectenemy()
{ if(mangyanenemy!=NULL) ent_remove(mangyanenemy); mangyanenemy=NULL;
if(pan_backselectenemy!=NULL) pan_remove(pan_backselectenemy); pan_backselectenemy=NULL;
if(townlevel!=NULL) ent_remove(townlevel); townlevel=NULL;
}
let us know how it goes.