I think that there's two things which you're leaving out:
First, slanty lines. This was adequately covered by @Jaywalker but if you need a further synopsis: suppose in reference frame $R_1$ both $A$ and $B$ are at rest and $A$ emits a laser pulse at $B$, describing the trajectory $x = 0, y = c \tau.$ We transform to a reference frame $R_2$ moving in the $x$-direction with velocity $-v$ relative to $R_1$, meaning that both of these points $A$ and $B$ are moving forward in $R_2$ with velocity $+v~\hat x.$
The only way that relativity can prescribe the crucial property that "all reference frames agree on what events have happened" is if the light pulse is now moving somewhat forwards in the $\hat x$ direction too. This line has to become slanty, otherwise one reference frame will say "$B$ received the pulse" and the other will say "$B$ did not receive the pulse." And that would be enough to conclude "we can no longer do physics." So if we're going to keep doing physics, this line must become slanted.
In fact, let's imagine that $A$ emits this pulse in a "circle" in the $yz$-plane perpendicular to $\hat x$. As it expands it describes a "disk" shape over time. Well in $R_2$ that "disk" must all tilt forward and become a "cone." If you now imagine a uniform radiation in all directions, half is on one side of the disk and half is on the other. So in $R_2$, half must be within this cone and half must be outside of it. If you stare at that fact long enough you will derive a known effect called relativistic beaming: if a particle is uniformly radiating in its rest frame, then in a frame $R$ where it is travelling near the speed of light it "beams" almost all of its radiation in the direction that it's going. That's the formal name for these slanty lines. (If you actually understood this: congrats, most undergraduates struggle for a long time through some spinor mathematics in their senior year or their first Master's year to get this important effect.)
If you accept these slanty lines then you can derive the Lorentz transformation from those examples, just beware of one thing...
Second, getting the light back where it started. This is extremely important. You can view all of the effects of one big relativistic boost from $R_1$ to $R_2$ as coming from compounding tons of tiny "mini-boosts" which are much simpler. This mini-boost by a tiny speed $\delta v$ in the $x$-direction maps the tuple $$(w,\, x,\, y,\, z) ~\mapsto~ \left(w - x~\frac{\delta v}{c},\;x - w~\frac{\delta v}{c},\; y,\; z\right),$$where $w = ct$ is our new geometric view of time in relativity. Notice that the mapping $x \mapsto x - w~\delta v/c$ is exactly the $x \mapsto x - t~\delta v$ that you always see with Newtonian reference frames, and the only new effect is that this symmetrically happens with the time coordinate $w$ as well.
You can view this as saying: if two clocks in $R_1$ are in-sync but are separated in the $\hat x$-direction, then in $R_2$ they will inevitably be out of sync. In fact whenever you accelerate, you see in-sync clocks come out of sync if they are spaced in the direction that you are accelerating. Length contraction and time dilation are just the summed-up effects of this de-synchronization.
Therefore it does not matter just yet when the light is going perpendicular to the direction that we are boosting, but it will become massively important if you want to calculate length contraction that you fire the light pulse to the front of the spaceship, reflect it off of a mirror, and then have it get detected by a detector at the back of the spaceship. Because this detector is in the same place as the source of the light, we do not have to care about how the clocks at the emitter and absorber have desynchronized in $R_2$: they simply haven't, they are the same clock! This means that your time expression in $R_2$ will look like $L'/(c + v) + L'/(c - v) = 2\gamma^2 L'/c$ whereas your time expression in $R_1$ is $2L/c$, even after including time dilation we get $L' = L/\gamma.$ If you do not get the light back where it started, then you will not get this result because you will be assuming that the clocks stay synchronized between $R_1$ and $R_2$, whereas the whole point is that the clocks desynchronize.