Need for diodes in opamp comparator
The circuit shown is actually a bad example of a sometimes good idea. If you look up the data sheet for the LM741, you'll see that the maximum allowed differential input (the difference between the two inputs) is +/-30 volts, while the maximum input voltage on any input is +/- 15 volts. So as long as the inputs are within the maximum range their difference is also within the maximum limit.

And I can't help but add that the circuit is not good practice in that it uses a general-purpose op amp as a comparator. For any sort of high performance, you should always use a dedicated comparator - but then again, for any sort of high performance anything you don't use a 741. But I digress.

Using protection diodes is actually a good idea for op amps which are expected to saturate, that is, drive their outputs close to the power supply voltages. Op amps depend on their input transistors being well-matched and well-behaved in order to produce good results. Driving the inputs to a large voltage difference is bad in both departments, and some op amps can require milliseconds to fully recover when the voltages get back to normal. So high-speed, high-precision circuits which experience large transients can benefit. A good example of such a circuit is the output amplifier for a high-speed DAC.

Real comparators, in contrast, are generally designed with large input differences in mind, so input diodes are not usually needed. The exception to this rule is a circuit which may produce input voltage higher than the power supply voltages, such as any circuit which monitors AC power lines. In this case, the diodes protect the circuit if a pathological input condition occurs.