Knock is when the petrol explodes prematurely due to compression. This causes the piston that is rising to rattle around and knock on the sides of the cylinder. Very bad. Will destroy an engine quickly.
Senses when the above is happening. If the ECU is any good it will then retard the timing a little to make the spark do the igniting rather than compression.
Great answers @Lunchmoney couldn't explain it better myself.
Even some aftermarket ECU's do not come with a knock sensor. By trimming back fuelling, ignition and boost to within safe levels you should not need it.
The Knock sensor is there to protect the engine should the fuel start to prematurely ignite. Running a piston against the crank in reverse by igniting too early is not going to do the engine much good at all.
It's amazing how quickly the knock sensor cuts in, and it has saved many highly tuned project cars from being destroyed.
The knock sensor detects preignition and detonation, potentially damaging forms of abnormal combustion.
When human ear can't detect these problems, the sensor works well.
A car still can run without it but it is, of course, an essential thing.