That is the lever that is meant to trigger your Z-Endstop. The variant used in your case is on the cheaper end and is meant to look similar to this QIAOH KN12-1 limit switch:
You will either exchange the endstop as a whole, somehow reattach the/a lever or change the physical position of the endstop so that the moving X-axis is triggering it (again).
Replacement & Wiring advice
Pretty much any switch that can have both an NC/NO (normally closed/normally open) state will function in its state, but it is usually a good idea to have all safety switches (like limit switches) be NC types and have the firmware detect the loss of signal as a safety feature. In case of a broken cable, this will automatically force the machine to halt, instead of keeping the machine moving despite having reached the maximum position.
It is even possible to wire up a number of redundant switches into one circuit. For NC setup, all the switches need to go in series, so that any switch getting toggled cuts the signal at that point. On the other hand, if only NO switches are used, they have to be wired in parallel: the signal passes when any number of switches is closed.
NO switches, because they are parallel, do cost us in the security department, as a broken lead does not halt the machine's use, but they are easier to troubleshoot as a broken component only takes out its specific arm of the parallel circuit. On the other hand, the NC-series does give us the broken lead security, but a single broken component that stays switched to open disables the whole series and identifying the broken component can take more time.
As you can imagine, some clever electronics allow us to use us to turn an NO into an NC and vice versa. This clever piece is a NOT-gate, sometimes also called inverter. They take a logic signal and a supply voltage lead, and only allow the supply voltage to pass into their output if there is no signal in their input side. So, they allow using a NO switch as an NC switch or vice versa. In any case, the NOT-gate needs to be on the output side the switch(es) it shall invert as it only inverts the signal that happens before it in the circuit.
With this clever piece, one can use a combination of NO and NC switches, if one so desires: The NO and NC parts are to be wired separately in groups (the NC group in series, the NO group(s) in parallel). To combine the two signals, there are two ways: Either run the NO output through the NOT-gate into the NC circuit's input, putting it into the series (and making it technically function as a single NC-element), or put the NC group output signal into the NOT-gate and put both groups in parallel. In either case, the NOT-gate 'flips' the function of the switches to behave as if they were the other type: from NC to NO and vice versa.