Consider the definition of length. We may define it as the difference of the spatial coordinates between two points with respect to a reference frame, when it's temporal coordinates are the same. Basically length is the distance between two points when they are at the same time coordinate.
Thus the relationship between length with respect to two different reference frame may be obtained using the Lorentz Transformation for the spacial coordinates.
Consider, the following scenario, two reference frames A and B. A is stationary, while B is moving with a constant velocity v with respect to A. We assign x and t to the reference frame A, x' and t' to reference frame B.
Note I will be taking $c=1$ to the end.
Now consider at some t', we measure a length l with respect to B. The length will be equal to
Now let's write down the transformation equations for $x'_p$ and $x'_o$.
Now we know how x transforms and hence we will substitute them into our transformation equations.
Here I will consider a simple example, however it can be generalised further. For simplicity, let's consider measurements made at t'=0, between the points x'=0, and x'.
Now as we have taken $t'=0$, we may imply that $t=vx$ and from here we can rewrite our transformation equation as
This is going to give us
Adding the speed of light in we get
Similarly you can arrive at the formula for tube Dilation
Now by our definition what is x'? Length as measured by the moving frame, what is x? Length as measured by the stationary frame. The key here is in the definition of length and time, which brings in the concept of length contraction, and time dilation
Also you must remember that in Special Relativity we don't use time dilation and length contraction, instead we focus on Lorentz Transformations, which are the fundamental equations of Special Relativity.
A more clear explanation is given by Leonard Susskind, in The Theoretical Minimum lecture series.
Also here is a special relativity space time graph, which works on the principles of Lorentz transformations, which will physically show how the effects take place