It’s to stop them from slackening off. Ideally they should be there. Alternatively you can use a nyloc nut but most modern bikes have recessed nuts, therefore this wouldn’t be possible.
It’s not 100% essential, your brakes will still work but it’s best practice to have it. And when it comes to brakes it’s best to have them working and set up correctly. Or go brakeless ftw.