Jean Meeus addresses this in Mathematical Astronomy Morsels. To answer this we have to start by defining the question precisely.
Firstly, they can never line up in three dimensions because their orbital planes are all slightly different
Let’s reduce the problem to two dimensions and ask whether all the planets can have the same heliocentric longitude. Then, to simplify the arithmetic, lets say that two longitudes count as “the same” if they’re within 1.8° of each other.
Mercury and Venus comes within 3.6° arc centered in every 0.396 year. On each pass, the chance that Earth will also be within this 3.6° arc is 1 in 100. So, on average, the three inner planets line up every 39.6 years. The chance that Mars, Jupiter, Saturn, Uranus, and Neptune will all be within this arc as well on any given pass is 1 in 100 raised to the 5th power, so on average the eight planets line up every 396 billion years. Well that’s much more than the age of the universe. But if you lose the definition and say that they will be considered to be lined up if they are within 30 degree then probably they will line up in every 500 years.