JVNY said:
the train is entirely within the rectangle at all times
Once again, you're ignoring a number of issues lurking beneath this apparently simple and innocuous statement. Let's actually assign coordinates to events and do some math.
We'll call the time illustrated in your Figure 2 (when the front end of the train is just reaching the turnaround at the right end of the shunt for the first time) in the ground frame time ##t = 0##. And we'll call the spatial location of the left end of the shunt (where the middle of the train is at this instant in the ground frame) ##x = 0## in the ground frame. Then we have three events illustrated in Figure 2:
Event O: The middle of the train at the left end of the shunt, at ##(x, t) = (0, 0)##. This event is the spacetime origin.
Event F1: The front of train at the right end of the shunt, at ##(x, t) = (40, 0)##.
Event R1: The rear of the train, still well to the left of the shunt, at ##(x, t) = (-40, 0)##.
The coordinates of these events in the right-moving train frame (in which the train in its entirety is at rest at all these events) are:
Event O: ##(x', t') = (0, 0)##.
Event F1: ##(x', t') = (50, -30)##.
Event R1: ##(x', t') = (-50, 30)##.
Note that these ##t'## values are offset by 30 from the "W" times in your Figure 2. This is for convenience.
We can already see that, if we are talking about "how things are" in the right-moving train frame, we have to adjust for the relativity of simultaneity; the above three events happen at different times in this frame. First, let's take the easy adjustment: at time ##t' = -30## in this frame, the length of the train is 100--because the center and rear of the train are at rest in this frame between ##t' = -30## and the times of the events above in this frame, so their ##x'## coordinates don't change. That means that at ##t' = -30## in the train frame, the center of the train is at ##x' = 0## and the rear of the train is at ##x' = -50##, so the train's length is 100. So far, so good.
Now let's look at the way things are at time ##t' = 0## in the right-moving train frame. The front of the train has been moving to the left, in this frame, for 30 units of time. Its speed is ##(0.6 + 0.6) / (1 + 0.6 * 0.6) \approx 0.88##, so in 30 units of time it will move ##30 * 0.88 = 26.5## units of distance. That means that, at time ##t' = 0## in this frame, the front of the train will be at ##x' = 23.5##. Furthermore, the right end of the shunt, which was co-located with the front of the train at ##t' = -30##, has also moved to the left at 0.6c, so at time ##t' = 0##, it will have moved ##30 * 0.6 = 18## units of distance and will be at ##x' = 32##. So the train at time ##t' = 0## consists of two segments: a segment from ##x' = -50## (the rear end) to ##x' = 32## (where the right end of the shunt is) that is at rest, and a segment from ##x' = 32## to ##x' = 23.5##, which is moving to the left at 0.88c. The first segment is 82 units long, and the second has a length contracted length of 8.5, which equates to a proper length of 18 (the gamma factor is 2.125), so the train's total proper length is still 100.
Finally, let's look at the way things are at ##t' = 30## in this frame. Here the front of the train has moved another 26.5 units of distance, so it is at ##x' = -3##. The right end of the shunt has moved another 18 units of distance, so it is at ##x' = 14##. The train is thus divided into two segments again, the first from ##x' = -50## to ##x' = 14##, which is at rest, and the second from ##x' = 14## to ##x' = -3##, which is moving to the left at 0.88c. The first segment is 64 units long, and the second has a length contracted length of 17, which equates to a proper length of 36, for a total proper length of 100, once again. Notice that at this point in the right-moving train frame, the center of the train still has not reached the right end of the shunt, so we are still at an earlier time than your Figure 3, which we discuss next.
Now let's switch to your Figure 3 and label the key events there and give their coordinates in the ground frame. All of these events happen at time ##t = 40 / 0.6 = 66.67##, since that is how long it takes for the front end of the train, at 0.6c, to cover the distance 40 from the left end of the shunt to the right end. So the events and their coordinates are:
Event R2: The rear of the train is at the left end of the shunt, at ##(x, t) = (0, 66.67)##.
Event C2: The center of the train is at the right end of the shunt, at ##(x, t) = (40, 66.67)##.
Event F2: The front of the train is at the left end of the shunt, at ##(x, t) = (0, 66.67)##. Note that this event has the same coordinates as event R2, since the front and rear ends of the train are co-located at this event.
The coordinates of these events in the right-moving train frame (in which only the rear half of the train is at rest in the period between the previous set of events and these, in the ground frame) are:
Event R2/F2: ##(x', t') = (- 50, 83.33)##.
Event C2: ##(x', t') = (0, 53.33)##
Similar to what we did above, we can figure out where the rear and front of the train are, in this frame, at the time of event C2, and where the center is at the time of event R2/F2. At time ##t' = 53.33##, 23.33 time units have elapsed since event R1 above, so the front of the train has moved an additional ##23.33 * 0.88 = 20.5## units of distance, and is at ##x' = -23.5##, and the right end of the shunt has moved an additional ##23.33 * 0.6 = 14## units of distance and is at ##x' = 0##. Of course the latter is exactly what we expect since the center of the train is at the right end of the shunt at this time in this frame. So the train consists of two segments, one from ##x' = -50## to ##x' = 0##, and one from ##x' = 0## to ##x' = -23.6##. The latter segment's proper length is ##23.6 * 2.125 = 50##, so the train still has a total proper length of 50 at this time.
Now let's look at event R2/F2. Here an additional 30 units of time have passed in this frame since event C2, so the front of the train has moved 26.5 units of distance and is at ##x' = -50##, as expected; and the center of the train has also moved 26.5 units of distance to the left and is at ##x' = -26.5##. The right end of the shunt has moved 18 units of distance from event C2 and is at ##x' = -18##. So the train consists of two segments, one from ##x' = -50## to ##x' = -18## at rest, and one from ##x' = -18## to ##x' = -50## which is length contracted by a factor of 2.125 and so has a proper length of ##32 * 2.125 = 68##. So the train's total proper length is, once more, 100. And from this point on in this frame, the front and rear ends of the train are touching, so the train continues to form a "loop" with two segments having lengths as just given, and its proper length remains 100.
We can do a similar analysis in the left-moving train frame--the frame in which the portion of the train moving to the left in the ground frame is at rest. Here the Lorentz transformation is the inverse of the one we did above, so the event coordinates are:
Event O: ##(x'', t'') = (0, 0)##.
Event F1: ##(x', t') = (50, 30)##.
Event R1: ##(x', t') = (-50, -30)##.
Event R2/F2: ##(x'', t'') = (50, 83.33)##.
Event C2: ##(x'', t'') = (100, 113.33)##.
Up until event F1 in this frame, the entire train is moving to the right at 0.88c (gamma factor 2.125). So we can evaluate the total length contracted length of the train in this frame at time ##t'' = 30##, since it will be the same at any time up to then (the entire train will be length contracted by this factor). At this time, the rear end of the train will have moved for 60 units of time at 0.88c, or about 53 units of distance, so it will be at ##x'' = 3##. That means the length contracted length of the train is 47 units, for a proper length of 47 * 2.125 = 100.
The next time of interest is ##t'' = 83.33##, the time of event R2/F2. The rear end of the train will have moved a distance 53.33 * 0.88 or 47, so it will be at ##x'' = 50##, as expected--co-located with the front of the train. But now we need to know where the right end of the shunt is at this time in this frame. It was co-located with the front of the train at event F1, and it moves to the right at 0.6c, so it will have moved a distance ##0.6 * 53.33 = 32## and be at ##x'' = 82##. That means the train consists of two segments, one of length 32 at rest, and one of length 32 that is length contracted by a factor 2.125, so again the train has a total proper length of 100. And, once again, from this point on in this frame, the front and rear ends of the train touch and it continues to form two segments of the same lengths.
(Note, btw, that event C2, where the center of the train reaches the right end of the shunt, happens later, at time ##t'' = 113.33##, which means that at the time of event R2/F2, the center of the train is still moving to the right. This is to be expected since the length of the segment of the train that's at rest is only 32 in this frame.)
So, when the math is done properly, it is evident that the proper length of the train is always 100. There is no justification for any other number.