The first thing you need to do is figure out whether this problem needs to be resolved in-character or out-of-character. Is the warrior's player doing this because the player enjoys this kind of PvP activity? Or is he doing it because he thinks it's what his character would do?
If it's the latter, then you should take a look at My Guy Syndrome, then use the answers there to help you discuss the issue with the player. If it's the former, then you need to sit down with the player, away from the game, and ask him why he's so invested in attacking you. Explain that this isn't fun for you, and that you want to work with him to find a way to support his character's backstory without having to spend all your time unconscious and not participating in the game.
For example, in my current game, my character and another character don't get along (though the player and I are good friends). My character frequently "attacks" the other character, but those events are strictly roleplay - no dice are rolled and there's no in-game effect, just a fun interaction. Another possibility would be to have a third character get involved, someone the warrior respects. This third character could say to the warrior, "I know you hate mages, but we need the warlock to accomplish our goal. If you keep knocking them out in combat, you're putting the rest of us at risk." Roleplay solutions like these help the player feel like their backstory and RP choices are being respected, without negatively affecting other players' characters.
A few key points to keep in mind when having that discussion: RPGs are supposed to be fun for everyone involved, and the whole group is responsible for maintaining that fun. If this player's actions are preventing you from having fun, that's not fair to you (and potentially the other players, as one frustrated and upset player can often bring down the whole group's mood, however unintentionally).
Depending on the player's reaction to this discussion, you may need to get your DM involved. Talk to your DM privately (not with the warrior's player present, to avoid anyone getting ganged up on), and explain the situation and why it's frustrating to you. Ask the DM if they can do anything to mitigate the issue - perhaps to enforce these attacks as roleplay-only, or to help give a story reason for the warrior to stop attacking you.
TL;DR: Make sure My Guy Syndrome isn't the issue, then work with the player to find alternate ways to RP their character that don't negatively affect you.
Yes - you can use a reaction on your turn to cast this if you have one available
A reaction is an instant response to a trigger of some kind, which can occur on your turn or on someone else's.
Since hellish rebuke takes a reaction to cast, it obviously qualifies.
If a spell can be cast as a reaction, the spell description tells you exactly when you can do so.
The spell specifies that it can be cast
in response to being damaged by a creature within 60 feet of you that you can see
A common cause of getting damaged on your own turn is getting hit by an opportunity attack as a result of your movement1. This would be a valid trigger for the casting of hellish rebuke.
So, if it is your turn and you get damaged and you have a reaction you can cast hellish rebuke as a reaction.
Note: No bonus action spells on your turn before or after hellish rebuke
Note that this means that you cannot cast a bonus action spell on your turn after casting hellish rebuke. If you have cast a bonus action spell already, you cannot cast hellish rebuke during your turn at all2. However, casting a bonus action spell on your turn would not affect your ablilty to cast hellish rebuke as a reaction outside of your turn. This is confirmed by Jeremy Crawford here.
Note: This means you spend your reaction
If you use your reaction on your turn, you are not able to use another one until the start of your next turn3.
1thanks @NautArch
2thanks @goodguy5
3thanks @SteveBauer
Best Answer
Unfortunately, as awesome as this sounds, by the rules, it doesn't work. Hellish Rebuke is a reaction that you take
Not "in response to being hit", or "in response to being attacked". You actually have to take damage to use it.
You haven't taken the damage until you've subtracted it from your hit points. If that puts you on 0 hit points, then
At which point, you are incapacitated and can't use reactions.