all the components of a computer have to run on the same frequency
That's simply not true. Your computer would run at 60 Hz - that's the refresh rate of your monitor.
CPUs have internal cache which is significantly faster than RAM due to its proximity and technology used. It's way more expensive to produce cache and increasing its amount increases latency, so we can't put gigabytes of cache on a CPU, but modern CPUs have a few dozen MB of cache. It's even split into three levels. Lower levels are smaller but blazing fast, higher levels have more capacity but also more latency.
Processors try to operate on cache rather than RAM as much as possible due to its speed advantage. Programs are written with cache in mind too. The more recently some part of RAM was accessed, the more likely it's to be present in L1 (level 1) cache. When there's data that seems more relevant, previous values are moved to L2, then to L3, and only then to RAM. Similarly, if some data has to be read, the CPU will first check if it's present in L1 cache, then L2, L3, and only then RAM.
This description is a very simplified model, in reality there's much more going on due to the need to coordinate separate caches for CPU cores etc., but that's enough for the sake of answering your question.
Now, when CPU is waiting for data from higher-level cache or RAM, it won't idle. Its clock is completely independent from RAM's clock and it will still tick. It will try to execute following operations if they don't depend on result of current operation or even make an educated guess of the result and try to work ahead based on that guess. All that to avoid wasting time waiting for RAM.
You also seem to be assuming that RAM will deliver data every clock cycle. That's not the case. RAM modules have a number of latency parameters known as timings, with CL (CAS latency) timing combined with module's clock frequency being the most important ones. Clock/CL can be used as a rough performance indicator useful for comparison of modules of the same type (eg. DDR4 vs DDR4), with higher values being better. For example a 2400 MHz CL15 module is better than 2666 MHz CL18 module despite having lower clock frequency, because 2400M÷15=160 M operations/second and 2666M÷18≈148 M operations/second.
It's true that some clocks of some components run in sync. In particular, the IF interconnect in Ryzen processors runs at RAM speed. In 1st gen Ryzens one could overclock IF by increasing RAM clock at the cost of higher RAM latency (so that overall RAM performance is maintained and higher clocks can be reached even with cheaper modules). Newer Ryzens and Intels don't benefit that much from high-frequency RAM.
Going for higher RAM clocks makes a lot of sense if you want to squeeze more performance out of an integrated GPU. If you're going for a dedicated GPU and non-Ryzen 1xxx CPU, it doesn't make that much of a difference. Buying a CPU clocked higher than RAM definitely makes a lot of sense.