The Z button refers to the long, purple button at the top right corner of a GameCube controller; the rectangular, gray trigger located on the back of a Nintendo 64 controller; or the rectangular, white button on the back of the Nunchuk. It can also collectively refer to the ZL and ZR buttons, two circular white buttons on the top of the Classic Controller. ZL and ZR are also buttons on the Wii U GamePad, Wii U Pro Controller, New Nintendo 3DS, Nintendo Switch Pro Controller and Nintendo Switch Joy-Con. There is no Z button on the Wii Remote. On the GameCube, Wii U Pro and Classic controllers, the purpose of the Z button is to grab opponents, and holding it past the grab will shield the character. In Super Smash Bros. Melee, it's also used for grabbing items in midair. On the Switch Pro, Nunchuk and Nintendo 64 controllers, the Z button is used to shield.
When using a single Joy-Con in SSBU, the ZL or ZR button (depending on which Joy-Con is used) is not set to any action by default. Instead, SL is used for grabbing and SR for shielding. In this configuration, the L, R, ZL and ZR buttons cannot be set to grab.
In Super Smash Bros. Brawl and Super Smash Bros. for Wii U, the Z, ZL and ZR buttons can all be customized on their own to do other functions, while in Super Smash Bros. for Nintendo 3DS, ZL and ZR are coded to do the same functions as the R and L buttons, respectively. Prior to version 1.0.5 of the game, these buttons' functions were reversed, so ZL would trigger the same actions as L and ZR would trigger the same actions as R, though their functions outside of battle (such as in menus) were the same as in current versions. On the character selection screen in Smash 3DS, the ZL and ZR buttons are also used to scan amiibo to the lower screen and register them for battles.
In terms of Brawl's programming, the Z button on the GameCube controller is considered to be both a shield button and a standard attack button at the same time. This is known because nowhere in character movesets does the game check to see if a grab button has been pressed - it only checks for if a shield and an attack button have been pressed simultaneously. This explains why the Z button can execute both attack-based functions (natural combo continuations, smash charging) and shield-based functions (air dodging). It is currently unconfirmed if this is the case for the other games as well.