Safety reasons. In case the cirquit with the "buttons" may use higher voltages than 5V.
e.g. if the external cirquit has 24V/0V outputs, the 24V will not damage the 4021, because diode will not allow current to flow to 4021.
If the external cirquit has open collector outputs or uses 5V/0V outputs, then the diodes (1N4148 probably) are not required.