Is a knock sensor necessary?

My check engine light is on and I took it to autozone and they said it was a knock sensor. Is it necessary to replace it if I put 93 octane gas in there. I noticed knocking before when I was putting 87 octane in, but it seems to have stopped since putting premium in. I am a 96 subaru legacy.
Update: meant to say I have a 96 legacy, not I am.
3 answers 3