She found out they went and sacked Highgarden instead of defending Casterley Rock. She knows where both locations are.
She knows the route they'd have to travel to get all the loot back.
She knows, despite other magical travel speeds depicted in the show, that it is highly likely that she's going to catch a portion of the army en route.
I'm sure she would have preferred to catch the entire caravan, including the gold wagons and the whole army.
The fact that she was able to catch at least portion of the forces and the cargo wagons was simply a matter of time, distance and physical laws.
If, say, the Lannister force had taken a less direct route that wouldn't take them as close to a landing area for the Dothraki force, then that Lannister force would be in the field much longer and the greater speed and mobility of her forces would still allow them to merely continue on to intercept along the alternate route, probably catching even more of the caravan in the field. So, yes, it's good fortune that she caught them there, but if they weren't there, they would have just proceeded to the next route and caught them at that location.
Jamie obviously knew there would be some vulnerability, hence the discussion about needing to hurry the remaining train and the ability of one end of the force to help the other in case of attack. Given his ability to be a couple steps ahead, and never having encountered or actually knowing of the capabilities of the Dothraki or dragons, he was probably hoping their element of surprise would buy them enough time to get back before Daenerys would form a plan and get it into action. He clearly overestimated his own forces' ability to withstand an assault, given those things he did not know, as well.
Keep in mind that none of her troops were left guarding Dragonstone (I'm not clear how much use the remaining two dragons would have been had there been an attack while Daenerys was gone), and given how much of their fleet had fallen to Euron, ferrying the Dothraki was not without risk, as well. It's possible that those factors would have caused someone else to hesitate or form some other backup plan.
I don't think the fact that it worked out that way and she was able to hit them was logistically exceptional.