Everyone's situation is different, so it's hard to give an answer to that. Hopefully it helps to know that this happens a lot, to a lot of writers.
(I had an ex-friend/roommate once who tried off and on to stop me from writing. She wanted to write movie and TV scripts, and that was great, but me wanting to write novels not so much. It was okay if I wrote fanfic, but not original fiction. Once when I was at home working on The Element of Fire, she saw what I was doing and said, "Oh, you know you'll never finish that."
Well, I did, and it was published in 1993 by Tor Books.)
Another question that's impossible to answer is why do people do that?
It's hard to answer because it's all different reasons.
Some people probably don't know they're doing it and/or couldn't explain why if you asked them. Some people might feel jealousy that you're writing, annoyance that you're paying attention to a screen or a piece of paper rather than them, or they're uneasy because they don't understand your desire to write.
Sometimes it's about power and control. Stop doing what you're doing and do what I want you to do. Stop writing what you're writing and write what I want you to write. Or else.
Sometimes it's about the type of writing you're doing. Writing literary fiction is great, but people will try to discourage or stop you from writing SF/F or mystery or romance or fanfic. I've had that happen to me. Or writing fanfic is great, but people will turn abusive if they catch you writing original stories. I've had that one happen too.
(Your fanfic is great but your original writing is worthless. Original writing makes you a hack, you're a bad person, you're disrespecting other fanfic writers who don't want to write original fiction. Stop, just stop. Or else.)
If you're a woman, sometimes people just want you to stop.
Sometimes it's concern. If you write, you'll be rejected and it will hurt so just stop. Sometimes it's concern trolling. Oh, I know you'll be rejected and you just won't be able to handle it, you're weak because I tell you you're weak, so just stop.
There are a lot of reasons for this and sometimes even if you know the person very well, you can't tell what their reason is. But sometimes there's only one thing you can do about it.