## They do not stack ##
The first bullet of Flames of Phlegethos states:
> When you roll fire damage **for a spell you cast**, you can reroll any roll of 1 on the fire damage dice and use the new roll.

And thus it can only apply to damage rolls of spells you cast. The other bullet however, states:
> Whenever you cast a spell that deals fire damage ... until the end of your next turn ... any creature within 5 feet of you that hits you with a melee attack takes 1d4 fire damage.

The damage from this is not you casting a spell, it simply happens when you are hit by a melee attack. The 1d4 additional damage is not part of the spell's damage because, though it does rely on the spell to exist, it is not part of the spell's description. The extra 1d4 fire damage are the feat's own damage roll.  

Because these dice are not part of the spell's damage roll these parts of the feat do not stack with each other.