Flameskulls weren’t among the original undead creatures of Advanced Dungeons and Dragons; they existed only in supplementary material until the fourth edition of D&D, when they first appeared in the Monster Manual. I can’t help thinking of them as being comical and cartoony (It’s a skull! That’s on fire! And hovering! And talking to you!), but in fact they can be a dangerous foe, especially to low-level characters.
Being undead, they have to be saddled with some sort of compulsion. Following the fifth-edition MM flavor text, their compulsion is obedience—specifically, to their duty of protecting a place, item or person. Because they’re bound to this duty, they have no self-preservation impulse; if they must fight, they fight till they’re destroyed.
And as it happens, it’s tough to destroy a flameskull: its Rejuvenation feature causes it to re-form, fully healed, one hour after being reduced to 0 hp, unless its fragments are sterilized with holy water or a dispel magic or remove curse spell. So an unhappy party of adventurers may vanquish a flameskull in order to entire a forbidden area, only to find that they have to fight it again on their way out. (Of course, this raises the question of whether a flameskull that’s sworn to keep them out of a place has any duty to keep them from leaving that place once they’ve already been in it. Play that one as it lies, dungeon master.)