Does this ever actually happen though? I'm not aware of variable length passenger trains along a single route. And the stations for boarding are only so long.
More often what happens (London) is the inverse. They’ll take two carriages off and squeeze you in tighter. Mornings always 10 carriages comfortably seated? So, Let’s take two off and let them stand for their expensive season pass.
Not your ideal train system, but happens in India. Quite often.
Many rail networks are designed for trains of a specific length. Primitive signalling systems risk trains colliding if trains are longer than the design length, or there are places a longer train would get stuck (a pair of long trains each cannot move forward because each requires the other to move first due to the design of the signalling and safety systems)
You can definitely run shorter trains though.
IIRC the NEC in America can accommodate 16-car trains but not all trains are that long.
There is no automatic process but it common to add cars for events, school trips or other organized groups.