"bugsymike" ^^ is correct about how the upper shift lever (the part that sticks out of the shifter boot/gaiter) is attached to the lower shift lever (the part that sticks out of the gearbox/transmission (normally hidden from the driver), however, the 124 Spider has a remote gearshift mechanism that changes the way the lower shift lever is located/attached.
There was a similar thread about a shifter problem and it's solution
on Jul 13, 2023 - see Similar threads section below.
Here's a few illustrations showing how the shifter lever and it's associated parts go together that will hopefully help :-
Early type of 5 speed remote control transmission- ball on end of part no. 4163982 is iirc pressed-on (if it's the plastic type) and not available separately. Some levers had a metal ball, can't remember if it was machined on lever or pressed on. If detached, clean thoroughly and refit with epoxy or similar.
__________________________________________________
2 types of 5 speed transmission gearshift arrangements - top is early non-remote type, bottom is later later remote linkage type (same as above pic) :-
________________________________________________________
Even later type of remote control gearshift, which I suspect is what is fitted on OP's car - pressed-on ball at end of gearshift lever has been replaced by a plastic? pivot (see red arrow) which is held in place by a nut and washer, (end of shift lever is now threaded). This plastic pivot fits on the end of the gearshift (see blue arrow). The shift lever is assembled and inserted upwards into the remote control housing as shown by the yellow arrow. Some remote control housings have a metal access plate attached to the end of the housing (see green arrow).
_________________________________________________
Enlargement of Op's 3rd picture, which seems to show the detached gearshift lever pivot ball (see red arrow) just below the gear selector relay rod (see my 2nd illustration for a list of what each part is called) :-
Incidentally, Op's 2nd picture seems to show some parts incorrectly assembled - the white plastic parts are used to attach the upper (detachable)gear shifter lever to the lower geat shift lever ( as "bugsymike" has already explained), they certainly don't fit on the lower part of the shift lever where it engages with the gear selector relay rod.
Now, how to fix the problem?
I think OP may have to remove the remote gearshift housing unit (a.k.a. gearshift mechanism housing) from the top of the transmission in order to reassemble everything correctly as indicated by the yellow arrow in pic 3 above. And as "bugsymike" has suggested, there may be a removeable plate (sheet-metal, painted black) on the top of the transmission tunnel (iirc, the centre console may need to be removed to remove this access plate) that will allow better access to remove the remote gearshift housing (4 x 13mm headed bolts).
Alternatively, iirc, it should be possible to do the job from underneath, without removing the remote gearshift housing but will likely need to disconnect the front of the driveshaft (propeller shaft) to gain access to the underneath part of the remote gearshift - there's no need to disconnect the Guibo/rubber doughnut coupling, the front of the shaft is on a splined coupling just behind the coupling, so just withdraw it. Then there's a plate with 3 x 10mm headed nut/setscrews under the r/gearshift housing, which, when removed, will allow removal/refitting of the gearshift lever, pivot ball/spring etc. as one unit. This is probably the easiest and fastest method.