Here are some spacetime diagrams to explain why the time dilation formulae don't work here, and why the relativity of simultaneity is important. I've done this for a simple out-and-back twin paradox with instantaneous turnaround and a constant velocity of 0.6c. The extension to more complicated cases is messy, but fundamentally the same.
First, here's a spacetime diagram of the stay-at-home clock (blue worldline) and the traveling clock (red worldline) in the frame of the stay-at-home:
The turnaround happens at time ##T##. But now let's think about the outbound frame, the frame in which the traveling clock is at rest as it travels to the right. The turnaround happens at time ##T'=T/\gamma## in this frame. But the Lorentz transforms tell us that ##T'=\gamma(t-vx/c^2)##, which is to say that "at the same time as the turnaround according to the outbound frame" is a
sloped line on this graph, satisfying ##t=T'/\gamma+vx/c^2=T/\gamma^2+vx/c^2##. That's the dashed line in the diagram below:
The dashed line intercepts the stay-at-home clock's (blue) worldline at ##t=T/\gamma^2##. This is exactly consistent with time dilation - the traveling clock experiences ##T/\gamma## of elapsed time, and measures ##1/\gamma## less time on the stay-at-home clock.
Now let's turn our attention to the inbound frame. The maths here is a bit messier. The turnaround in this frame happens at ##T''=\gamma(1+v^2/c^2)T##. Again, the Lorentz transforms tell us that ##T''=\gamma(t+vx/c^2)##, or ##t=(2T-T/\gamma^2)-vx/c^2##. Again, this is a sloped line, but it is
not the same sloped line as above - it slopes in the opposite direction.
Again, this is consistent with the time dilation formula. The traveling clock experiences time ##T/\gamma## on the inbound leg, and measures the stay-at-home clock to experience less time by another factor of ##1/\gamma##.
But now we can see what's gone wrong. The time up to ##T/\gamma^2## on the stay-at-home clock is "during the outbound leg" according to the outbound frame, and the time after ##2T-T/\gamma^2## is "during the inbound leg" according to the inbound frame. But because we changed our definition of "at the same time as the turnaround", to naively apply the time dilation formula is to forget about the middle portion of the worldline. This is why there is no problem with the behaviour of the stay-at-home clock - it ticks 2T times. But if you don't account for the relativity of simultaneity you have forgotten about ##2Tv^2/c^2## of them.