I agree, that Williams was lucky in many ways. But it’s not just luck.
Of course it is not just luck. If his music wasn’t that good it would not have become classics. We see this on lots of more recent films that were huge successes but their scores hardly will become real classics.