Let's review the background: season 4 before the alliance with Hector was Walt trying scheme after scheme to get to Gus and none of them worked. Was he sure the Hector plan would work? I'd say no. It was just the best idea available at the time.
So you could say he was lucky, but it's not like he came up with this one great plan and eliminated Gus on the first try.
After a string of failures (mostly caused by Jesse not being fully cooperative), he finally got Jesse back on his side and then what happened? Even then the first attempt was a failure, because Gus guessed the existence of the car bomb based on nothing but Jesse's assertion that Brock was poisoned!
The next plan, the one that worked, was formed after Walt learned that Gus had personally visited Hector to gloat about the death of the last of Hector's relatives. That was a clue that Hector brings out a different side of Gus - different from the calm, careful, practical Gus that Walt could not defeat. Hector made Gus a little bit crazy. It wasn't a big leap to assume that Gus might want to be present at Hector's death.