What does the diode do in this switch and lamp?
See the wires labeled "row" and "column"?

What you have there is detail drawings of single cells of matrixed switches and lamps.

The purpose of the diode is to steer the current though the addressed devices only, by disallowing detour paths.