Why do some electromagnetic waves continue travelling while others disappear? Cosmic background radiation emitted when the Universe was very young still exists. But my wifi signal seems to disappear a short distance from my apartment. Why?
Electromagnetic radiation will continue to travel until it is absorbed.  Some of your wifi signal is escaping to space where it may continue traveling for a very long time.
However, the strength of your wifi signal will degrade with distance according to the inverse square law.

So if you double the distance between your device and the wifi transmitter, your signal will be reduced by 3/4. When you move far enough away, eventually your signal will degrade enough that your device will no longer be able to decode the signal.  So the radiation doesn't &quot;disappear&quot; but instead, your device will just be able to pick up less of the energy.  Of course, if you separate the device and transmitter by a concrete wall, some of the signal will actually be &quot;disappearing&quot; as it is absorbed by the wall.
The CMB (Cosmic Microwave Background) on the other hand, was not emitted from a point source, and is not subject to the inverse square law.  Instead, as wikipedia points out, the CMB

is very nearly uniform in all directions, but the tiny residual
variations show a very specific pattern, the same as that expected of
a fairly uniformly distributed hot gas that has expanded to the
current size of the universe.

So one can imagine that wherever we are in the universe, we can point an antenna in any direction and get about the same amount of signal (excepting Doppler shift) from the CMB. Of course, if we point our antenna towards existing matter, we will expect some or all of the CMB to have been absorbed in that direction. In many cases, astronomers can tell a lot about the composition of gas in absorption based on the narrow frequencies of the CMB that was absorbed. Back in the early 2000s, I spent quite a bit of time looking for cosmic formaldehyde in absorption lines of the CMB near the center of our galaxy, as an indicator for early star formation.