It is a factor of heat and energy. The higher the clock speed, the more heat and energy, the more cores, the more things generating heat and energy on the chip. The more higher clocked things they put on a chip, the more heat they have to deal with. Better heat sinks/coolers cost more money. You can have the 8 core chip at a really high clock speed, but now you need a way to cool the chip if it is running all the cores on full load at that clock speed. Sometimes there is too much heat generated.
The higher the clock speed, the more power you need. This can mean if you don't have enough power, the CPU becomes unstable and malfunctions. There is also a limit to how high you can get the chip to perform despite all the power in the world, eventually it becomes less efficient to pump more power through to try and get a few more Mhz.
Neither is dependent on each other, but they do effect each other in terms of heat and power usage.
There is also I believe some stuff on leakage and interference, but that is more significant in how many cores can fit on this chip and power efficiency when trying to get more clock speed in more an architectural thing in the design side and stability of the chip.
Now onto programs, programs run in threads. A thread is basically a list of things to do/instructions. 1 core will process 1 thread at a time, be aware that modern processors will switch between threads very quickly, but they are essentially only working on 1 thing at a time. If you have 2 cores, you can go through the instructions of 2 separate threads at the same time. How fast you can go through the instructions is based on (work that can be done each cycle * how many cycles can be done in a second) Hz, the measurement we use for cycles per second. IPC, instructions per clock, how many things we can do each cycle.
A program can have many threads, or one. But programming an application to do more than one thing at a time is complex, typically when you are doing things you are thinking about doing them procedurally, not all at the same time. So most programs have a single thread, so no matter how many cores you have, you will see no benefit(this is only if you only had 1 thing running, if you have a dozen programs/services running, that is at least a dozen threads). But if you split workload evenly between 2 threads, you have 2x the performance if you have 2 cores to process them at the same speed. How fast the cores are, again, limited by money, architecture, electricity, and how much heat you can disperse. They make many flavors of CPU's, because more cores == more cost. Higher clock cycle == higher cooling. Also, not every wafer is equal. There are defects in every batch of CPU's, and the defects can determine if they can run high clock speeds at a stable level, sometimes they even have to disable cores due to defects. This is binning if I remember wordage right, which is why sometimes you see the same cpu, sold at different price points with different clock speeds as different models. Or the same models, but a core disabled. Some of them are binned down because they need more for demand to hit a pricepoint, some because they are just slightly "defective". Not to say they don't run at advertised speed fine, because they will "'m certain, but they may not be capable of more due to detected defects.
This is how I understand it, but I am less proficient in the Hardware aspect of computers than the software side.