Maybe instead of having the collision mask change when taking damage, you could set a “hit cooldown” variable that resets to a certain value and increases over time, and will only allow health to decrease if it’s above a certain number? Just a thought, I hope this helps! :)
There actually is already a hit cooldown present, as long as the character flickers red after getting hit, you shouldn't be able to get hit again.
Have to say, I have difficult times reproducing the collision bug myself, even after getting hit constantly when right behind the wall.
Maybe I'll give it another look at it to see if it's possible again.