As Petr Polovodov says, this is a classical problem, and depending on how comfortable you are with PDEs, it's... actually still hard to understand.
First things first, note that waveguides are not resonant devices. (However, the lowest-order mode, the dominant mode, has a cutoff frequency determined by resonance, and this gives us e.g. the transverse resonance technique for finding cutoff frequencies.) When you see the sinusoidal patterns in the transverse (xy plane for propagation in z) plane, that is not wave propagation, and it's also not related to the freespace wavelength of the wave, or to the phase constant of the wave. It's just the amplitude envelope in the transverse direction, so make sure you don't fall into the trap of thinking that only certain frequencies (harmonically related) will "fit" into the waveguide.
A short answer to your question is "the wave equation and boundary conditions allow it." An answer to a small sub-problem is that in rectangular waveguides, you can equivalently view some propagation modes as composed of two independent bouncing waves which combine to give the actual standing wave. It's a case where it's indistinguishable from the scenario, so there's no harm in preferring one interpretation or the other.
Another perspective: When I think of boundary conditions, I think of voltages in a circuit. If we know the voltage at A is x and the voltage at B is y, then the circuit is determined and we can solve it. The voltages throughout the circuit are considered as being due to those known points if they're connected to a power source. Same thing for boundary conditions, especially because those voltages are actually boundary conditions anyway.
Math
First order of business, recall that for phasors, the source-free curl equations are:
$$
\begin{align}
\nabla \times \mathbf{E} &= -j\omega \mu \mathbf{H} \\
\nabla \times \mathbf{H} &= -j\omega \epsilon \mathbf{E}
\end{align}
$$
Plane waves of course are a particular subset of the solutions to the wave equation, and the Helmholtz wave equation in particular. The wave equation is derived from the curl equations, but the sets of equations are independent, so you can use both (curl and wave) to determine a system. The E and H fields both obey Helmholtz equations of the form:
$$
\nabla^2 \mathbf{E} + k^2 \mathbf{E} = 0
$$
Because the curl equations and vector wave equation are extremely general, we restrict our attention to solutions of the form:
$$
\begin{align}
\mathbf{E} &= (\mathbf{e}(x,y)+\hat{z}e_z(x,y))e^{-j\beta z} \\
\mathbf{H} &= (\mathbf{h}(x,y)+\hat{z}h_z(x,y))e^{-j\beta z}
\end{align}
$$
Where $\mathbf{e},\mathbf{h},e_z,h_z$ are complex amplitudes with magnitude and phase, and the spatial variation must be sinusoidal according to $e^{-j\beta z}$ for some unknown constant $\beta$ in the $z$-direction. (For TEM waves, $\beta$ is the familiar phase constant, $2\pi/\lambda$; in general, it is not.) This is still very general, the form given only enforces the sinusoidal requirement, both sinusoidal in time as well as space.
The above forms contain all solutions for TEM, TE, and TM modes of electromagnetic waves, including TEM plane waves, and even more complicated solutions. We distinguish between the $z$-component of the E-field or H-field and the transverse components $\mathbf{e},\mathbf{h}$, because we often have either $e_z=0$ or $h_z=0$ in practical problems, and the transverse components are often considered together anyway.
Note: The E-field and H-field components, and the general field vector directions, are unrelated to the direction of propagation. In plane waves, they form three mutually orthogonal vectors, but there's nothing that inherently requires them to have a relationship. Until we prescribe boundary conditions.
The cases of TEM, TE, and TM waves are special cases of the above form that allow us to simplify the solution to the curl equations and the wave equation. So, first let's use our general-ish form to simplify the curl equations to four coupled PDEs.
$$
\begin{align}
H_x &= \frac{j}{k_c^2}\left(\omega \epsilon \frac{\partial E_z}{\partial y} - \beta \frac{\partial H_z}{\partial x}\right) \\[1em]
H_y &= \frac{-j}{k_c^2}\left(\omega \epsilon \frac{\partial E_z}{\partial x} + \beta \frac{\partial H_z}{\partial y}\right) \\[1em]
E_x &= \frac{-j}{k_c^2}\left(\beta\frac{\partial E_z}{\partial x} + \omega\mu\frac{\partial H_z}{\partial y}\right) \\[1em]
E_y &= \frac{j}{k_c^2}\left(-\beta \frac{\partial E_z}{\partial y} + \omega\mu\frac{\partial H_z}{\partial x}\right) \\[1em]
\end{align}
$$
Solving these curl equations with the wave equation will give us our solution. In general, you develop a wave equation in one of the z-components, then use the curl equations to solve the other components. Except in TEM waves, where you use a Laplace equation in place of the wave equation for the z-components.
What we find for the transverse electric case, is that the $H_z$ component follows a "transverse" (2D) wave equation,
$$
\left(\frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2} + k_c^2\right) h_z = 0
$$
Where $ k_c^2 = k^2-\beta^2$, $k=\omega\sqrt{\mu \epsilon}$, and $\beta$ is determined by the boundary conditions. This applies for any TE case, not just inside a rectangular waveguide. For the transverse magnetic case, we find
$$
\left(\frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2} + k_c^2\right) e_z = 0
$$
Another general result, for all TM propagation modes.
Finally, if you solve for the TE modes in a rectangular waveguide by first solving the transverse Helmholtz equation with separation of variables, you get
$$
h_z(x,y) = (A\cos k_x x + B\sin k_x x)(C\cos k_y y + D\sin k_y y)
$$
And, with boundary conditions, the full z-component of the H-field is
$$
H_z = A_{mn} \cos \frac{m\pi x}{a} \cos \frac{n\pi y}{b} e^{-j\beta z}
$$
So we can plug this into the curl equations above and obtain expressions for $E_x, E_y, H_x, H_y$ for different values of integers $m,n$ (modes) in the form
$$
E_x = \frac{j\omega\mu n\pi}{k_c^2 b} A_{mn} \cos \frac{m\pi x}{a} \sin \frac{n\pi y}{b} e^{-j\beta Z}
$$
If you've got some experience with PDEs, these solutions shouldn't be all that surprising or unfamiliar. The $\cos$ and $\sin$ terms are responsible for the amplitude envelopes in the X and Y directions for the $x$-component of the E-field (where $x$ is taken to be in the direction of the long side for a rectangular cross-section, $y$ is in the direction of the short side).
So far, we haven't found that the fields must obey this form, but that they can. The way you excite the waveguide will obviously play a big roll in what modes are excited. But in general, in order to satisfy the boundary conditions, you need to have those sines and cosines in the amplitude envelope.