We don't, really. This line is a combination of two unrelated expressions, neither of which is terribly common.
"The stars line up" is a reference to astrology. Literally, it means that the planets have reached some alignment that is supposed to be meaningful in astrology--that the lining up of the stars has created a lucky moment. Figuratively, it just means "it was a very lucky moment" or "a wonderful coincidence."
"SHAZAM!" is actually a magic word from the Marvel universe. Saying the magic word transforms Billy Batson into Captain Marvel, a superhero. SHAZAM! is an acronym, because Captain Marvel combines the wisdom of Solomon, the strength of Hercules and Atlas, the power of Zeus, the bravery of Achilles, and the speed of Mercury.
Combine the two and it means "there was a piece of amazing luck, and a miraculous thing happened."