Every pendulum has a natural or resonant frequency, which is the number of times it swings back and forth per second. The resonant frequency depends on the pendulum’s length. Longer pendulums have lower frequencies.
Every time the first pendulum swings, it pulls on the connecting string and gives the second pendulum a small tug.
Since the two pendulums have the same length, the pulls of the first pendulum on the second occur exactly at the natural frequency of the second pendulum, so it (the second pendulum) begins to swing too. However, the second pendulum will swing slightly out of phase with the first one. When the first pendulum is at the height of its swing, the second pendulum is still somewhere in the middle of its swing.
As soon as the second pendulum starts to swing, it starts pulling back on the first pendulum. These pulls are timed so that the first pendulum slows down.
To picture this, it may help you to think of a playground swing. When you push on the swing at just the right moments, it goes higher and higher. When you push the swing at just the wrong moments, it slows down and stops. The second pendulum pulls on the first pendulum at just the “wrong” moments.
Eventually, the first pendulum is brought to rest; it has transferred all of its energy to the second pendulum. But now the original situation is exactly reversed, and the first pendulum is in a position to begin stealing energy back from the second. And so it goes, the energy repeatedly switching back and forth until friction and air resistance finally steal all of it away from both pendulums.
If the two pendulums are not the same length, then the tugs from the first pendulum’s swings will not occur at the natural frequency of the second one. The two pendulums swing, but with an uneven, jerky motion.