Does a hero lose the experience if he/she dies?
Yes, this appears to be exactly the case. See this thread:
PSA: The death penalty in Fire Emblem Heroes is a loss of any xp or level ups gained for that unit in the map.
Camilla died on a map after leveling to 11. Even though the rest of the team completed the level, she was lvl 10 in the next map.
Also, you can't "reroll" bad level ups with this method. You'll get the same stat growths next time you level, you just lose the xp.