So it sounds like you're confused about time dilation. You can complete this derivation without time dilation, but it requires some more advanced mathematics.
How does the train argument work?
The standard train argument works like this:
- We tell our students that everyone sees light move at the same speed $c$. We tell our students to be very careful comparing times on different clocks because of an effect that we will see in step (4), so we are going to carefully route all light to the same clock and see what it measures. We are then going to derive some rules to transform this into frames where that clock is moving horizontally on a train of constant speed $v$.
- We consider a light pulse which travels in the train in a vertical direction. It goes a distance $h$ from the ground to the ceiling, bounces against a mirror, and then travels the same distance back to the ground. A clock at the ground measures the time $\tau = 2h/c$ for it to travel this distance. But now in the frame that sees this thing moving, the principle of constancy of the speed of light demands that we have triangles of base $v~t$ and height $h$ and hypotenuse $c~t$, so we find $t=2h/\sqrt{c^2-v^2}$. We tell the students that this factor of $\gamma = 1/\sqrt{1-(v/c)^2}$ is a universal time-dilation factor, any frame which sees a clock moving sees it tick slowly by this factor.
- We consider now a light pulse which travels in the train in a horizontal direction. It goes a distance $L$ and again reflects off a mirror back to its origin, where a clock measures the time to travel this distance as $\tau = 2L/c.$ Now the calculation gets more fun, as we know that the time elapsed is $t = \gamma ~2L/c$ from the previous section, but that conflicts with the equivalent analysis: in this frame the relative velocity of the mirror and the light is $c-v$ and the relative velocity of the absorber and the light is $c+v$ and we would expect to find $$t=\frac{L}{c+v} + \frac{L}{c-v} = \frac{2Lc}{c^2-v^2} = \gamma^2 2 L/c.$$ We allow this discrepancy between $\gamma$ and $\gamma^2$ to sink in for a bit and finally we resolve the student's confusion: there is only one parameter here that can absorb the paradox and it is $L$, so we find that $\tau = 2 L/c$ and that $t=\gamma~2L/c = \gamma^2~2L'/c$ and this means that $L' = L/\gamma.$ There is evidently also a universal effect: if some frame thinks that two objects are not moving and are separated by a constant distance $L$ then every other frame which sees them both moving at speed $v$ thinks that the true distance between them is $L'=L/\gamma.$
- We finally return to this discrepancy about clocks at different locations by using two clocks that are in sync upon the train, at $x=0$ and $x=L,$ having the property that someone on the train at position $x=L/2$ sees both of them tick identically. We now just consider the forward half of that trajectory: the time elapsed in this frame is $\tau = L/c.$ We know that the ground frame must see the same light travel a distance $L/\gamma$ and that the time taken must be $$t = \frac{L/\gamma}{c - v} = \frac{(L/\gamma)~(c + v)}{c^2 - v^2} = \gamma~\frac Lc~\left(1 + \frac vc\right).$$We ask our students to think about why this is not $t = \gamma~\tau$ as we might expect given (2) above. If the ground frame saw these two clocks as being in sync, then the conclusion that $t=\gamma~\tau$ would be unavoidable, but we can see that actually we have $t = \gamma~\tau~(1 + v/c)$ and this must mean that we do not see those clocks as being in sync. In particular when the light pulse is emitted and the first clock reads $0$ we on the ground must think that the second clock reads $-vL/c^2$. We tell our students that this is a universal effect called "the relativity of simultaneity."
- We usually then derive the Lorentz transformation somewhat hastily. Our students at this point are uncertain enough that they accept the equation $x' = \gamma~(x - vt/c^2)$ without asking the very important question of why this factor is $\gamma$ and not $1/\gamma$ as might be expected from length contraction.
It looks like your teacher may have skipped through 2 and 3 in order to get to 4. The chief strength of the train argument is that it immediately shows you by the Pythagorean theorem where this factor of $\gamma$ comes from. It has several weaknesses including that when a student runs back through these ideas they start asking why $h$ wasn't length-contracted earlier, or asking why the Lorentz transform has $\gamma$ and not $1/\gamma$ for the transform of position coordinates, or we get to the velocity addition formula and we introduce hyperbolic tangents and it seems terribly ad-hoc. It also does not seem to introduce much causality into the system.
Deriving the Lorentz transform with matrix mathematics.
We tell our students that everyone sees light move at the same speed $c$. We then imagine that someone quickly turns on-and-off a light while they are moving at speed $v$. We draw a circle of the light around her, in her reference frame, pointing out that it is a distance $L = c~t$ around her in all directions.
Now we invite them to think about a reference frame in which this person is moving at some slow speed $v \ll c$. We draw the same circle, with a point at its center, this is where she was when she flashed that light on and off; but now she has moved forward a distance $v~t$. So we put a point very close to the center but perhaps slightly to the right and remind that she has not moved very fast relative to light. We now put points at the same distance $L=c~t$ around her, and we notice that the dots orthogonal to the motion are basically on the circle, but the ones "in front of her" from our perspective are also "in front of the light" and the ones "behind her" are also "behind the light".
We explain that what must be happening, given that she thinks that the light is hitting these dots "right now" while we think that the light "has already" hit these dots behind her and "is yet to" hit the dots ahead of her, is that we must disagree on when "right now" is at distant positions. We draw clocks on these dots reflecting our in-sync time T, she must see the clock in front of her show a slightly later time and the clock behind her show a slightly earlier time: the time when the light actually reaches the clocks, which is given by $L/(c\mp v),$ where the top operator $-$ is for the one ahead of her and the bottom is for the one behind her. Since $v$ is small we can Taylor-expand this as $L/c \pm Lv/c^2.$ We note that clocks are out-of-sync proportional to their distance and the velocity that she is going. This is where we get back to that causality aspect that we mentioned earlier: we say to the students, "So it is a strange feature of acceleration in our world that when you accelerate, you see clocks ahead of you by a distance $L$ tick faster at a rate $1+L~a/c^2$ and the clocks behind you tick slower at a rate $1-L~a/c^2.$ This is going to be important because we're going to see that in gravitational frames the 'correct' frames are free-falling, and for us to stay at a constant distance from Earth's center, Nature thinks that we are in a non-inertial frame accelerating upwards with acceleration $g$. Therefore all of the clocks in the satellites in the sky must seem to be ticking faster! This has been observed and is part of how GPS has to work."
Now comes the "advanced mathematics": it is not terribly advanced; it is linear algebra. We impose on students the desire to work with a space-unit dimension of time $w = c~t$ and dimensionless velocities $\beta = v/c$ and then observe that our present transform is this: when moving to a frame with velocity $v$ we used to use the Galilean transform, $$\begin{bmatrix}w'\\x'\\y'\end{bmatrix} = \begin{bmatrix}1&0&0\\-\beta&1&0\\0&0&1\end{bmatrix} \begin{bmatrix} w\\x\\y\end{bmatrix}$$where the $y$ is just to show this orthogonal axis. But now we see that we actually need something which for small velocities looks like,$$\begin{bmatrix}w'\\x'\\y'\end{bmatrix} = \begin{bmatrix}1&-\beta&0\\-\beta&1&0\\0&0&1\end{bmatrix} \begin{bmatrix} w\\x\\y\end{bmatrix}.$$We observe for the student's sake that now, instead of just one of these components mixing unilaterally with the other, the two are getting jumbled up together and it's hard to see what the effects of that are going to be on anything other than this uninvolved $y$-component as we accelerate towards $v\approx c.$ There are now two ways that I know of to get the right answer from this first-order matrix $F(\beta) = \begin{bmatrix}1&-\beta\\-\beta&1\end{bmatrix}.$
The first is to observe that $F(-\beta) F(\beta)$ should be the identity matrix $I$ as we should be able to transform to new coordinates and then back and recover our original ones. This matrix product is not $I$ but $I~(1-\beta^2).$ The minimal solution for mathematical consistency is therefore to distribute this factor evenly to get $L(\beta) = F(\beta)/\sqrt{1-\beta^2}$ which will be mathematically consistent and we recover $F(\beta)$ to first order in $\beta.$ This can seem "magical" to the student in an unpleasant way but I have met many who think "oh, that is very obvious!"
The second is more elaborate, we consider the matrix exponentiation $$\lim_{n\to\infty} \begin{bmatrix}1 & -\alpha/n\\-\alpha/n&1\end{bmatrix}^n.$$Here we clearly are trying to derive what the large-scale behavior must be by a sequence of $n$ small steps towards it. To do a matrix exponentiation we need eigenvectors: this is not hard as $[1;1]$ is an obvious one and symmetric matrices have orthogonal eigenspaces hence $[1;-1]$ is a logical next guess, and it works just fine. The eigenvalues are $1-\alpha/n$ for the first one, $1+\alpha/n$ for the second. This matrix exponentiation works out to$$\lim_{n\to\infty} \sqrt{\frac12} \begin{bmatrix}1&1\\1&-1\end{bmatrix} ~ \begin{bmatrix}1-\alpha/n&0\\0&1+\alpha/n\end{bmatrix}^n ~ \sqrt{\frac12} \begin{bmatrix}1&1\\1&-1\end{bmatrix} = \frac12 \begin{bmatrix}1&1\\1&-1\end{bmatrix} ~ \begin{bmatrix}e^{-\alpha}&0\\0&e^\alpha\end{bmatrix} ~ \begin{bmatrix}1&1\\1&-1\end{bmatrix},$$using the familiar limit that $\lim_{n\to\infty}\left(1 \pm \frac\alpha n\right)^n = e^{\pm \alpha}.$ Now we can introduce these functions $\sinh\alpha = (e^\alpha - e^{-\alpha})/2$ and $\cosh \alpha = (e^\alpha + e^{-\alpha})/2$ as the odd and even parts of the exponential function, in terms of which this matrix product takes the form,$$
\begin{bmatrix}\cosh \alpha&-\sinh\alpha\\-\sinh\alpha&\cosh \alpha\end{bmatrix}.$$Now one observes that a particle at rest in our frame would appear to be moving backwards with velocity $-c~\sinh\alpha / \cosh\alpha = -\tanh\alpha$ in this other frame, thus coming to a conclusion that $\tanh \alpha = \beta.$ We can then observe that $\cosh^2\alpha - \sinh^2\alpha = 1$ to find that $1 - \tanh^2\alpha = 1/\cosh^2\alpha$ hence $\cosh\alpha = 1/\sqrt{1-\beta^2}.$ Since $\sinh \alpha = \cosh\alpha \tanh\alpha$ we have $\sinh \alpha = \beta/\sqrt{1-\beta^2}.$ We show the interpretation of $\cosh\alpha$ as a time dilation factor and then transform the lines $[w; L]$ to be $[w'; L'] = \gamma~[w-\beta L; L - \beta w]$ to find $L' = \gamma L - \beta~(w' + \beta L),$ so at constant $w'$ these are spaced by $L' = \gamma L (1 - \beta^2) = L/\gamma,$ and we have derived length contraction as well.
Finally we derive the rules $$\sinh(\alpha \pm \beta) = \sinh \alpha \cosh\beta \pm \cosh\alpha\sinh\beta,\\
\cosh(\alpha \pm \beta) = \cosh \alpha \cosh\beta \pm \sinh\alpha\sinh\beta.$$From them we show that the composition of two Lorentz transforms is also a Lorentz transform with the summed components, from which the idea of adding "rapidities" to find velocities now naturally flows.