I’m sorry you are going through this, but, yes, masturbation is an intrinsically grave sin. The circumstances don’t change the fact that it is intrinsically sinful. It will always be a grave sin, even when life circumstances make it a big temptation.
The only thing that would make it not a mortal sin would be something that impacts the other two requirements for a sin to be mortal: full knowledge or complete consent.
So, for example, a young person who doesn’t realize what they are doing wouldn’t have full knowledge. Someone who has the habit so deeply engrained might have their ability to consent compromised.
Neither of those seem to apply in your case (from what you have described).
I agree with Denise that talking to a priest about this might be helpful for you. It’s a trial to be sure.