
Credit: Keychron
Switches are the basic building block of keyboards, and for this explanation I will be focusing on mechanical switches as show above.
These switches come in many materials and colors with different feels, spring weights, stem types from many different companies, but the basic components remain the same.

Credit: Das Keyboard
As the above diagram shows, a switch is made of five parts. The two housing pieces hold the switch together: the upper housing interfaces with the lower housing with plastic clips, sandwiching the inner-workings between. This allows for very cheap manufacturing without the need for screws or similar fasteners. These are made out of various types of plastic, the most common of which being polycarbonate, nylon, POM and UHMWPE, each of which offer certain advantages and disadvantages. For instance, polycarbonate is quite cheap but rough, which can impact the feel of the switch's actuation negatively. POM, in contrast, is more expensive, but gets smoother over use.

Left to right: polycarbonate, nylon, POM and UHMWPE. Credit: Digitech

Credit: Theremin Goat's Switches
The crosspoint, or leaf, is responsible for completing the circuit, so the switch emits data to the circuit board of the keyboard. It does so by the two pieces being kept separate by the stem in its default state. Once the switch is pressed, the stem moves out of the way and the two pieces of the leaf connect, completing the circuit.

Credit: Digitech
The next component of a mechanical switch is the stem, which is the part of the switch that fits into the plastic keycap you touch when you type. These parts come in three common varieties: linear, tactile, and clicky, and that variety is what determines what you feel when you press down on the key.
Linear switches are the most simple, having no feeling other than the resistance from the spring. This is because the plastic leg on the end of the stem that presses against the leaf is perfectly straight. Tactile switches, however, have a hump on that leg, which results in a noticeable bump when the switch is actuated. Clicky switches take the leg shape of a tactile switch, but introduce a new part: the click jacket. This "jacket" fits around the base of the stem, moving somewhat independently of the stem itself. Once the hump passes over the leaf, the jacket rapidly slides down the stem, hitting the bottom housing and making a click.

Credit: YMDK
The final part of the switch is the spring, which simply pushes the stem up so it can be actuated. Springs come in a variety of weights, requiring different amounts of force to push them down. This is largely a matter of preference, as some people like heavy springs so they don't accidentally press a key, whereas others might want to type as possible with the least amount of effort exerted.