They're not illegals. If you don't put them, when you have a B natural, you have to precise that it's a B natural and not a B flat (and the same thing applies with the F flat, the B sharped and the E sharped). They just make the music easier to read.