ذَلِكَ هُدَى اللّهِ يَهْدِي بِهِ مَن يَشَاء مِنْ عِبَادِهِ
...
This is the guidance of Allah with which He guides whomsoever He wills of His servants.
meaning, this occurred to them by Allah's leave and because He directed them to guidance.
Allah said;
...
وَلَوْ أَشْرَكُواْ لَحَبِطَ عَنْهُم مَّا كَانُواْ يَعْمَلُونَ
But if they had joined in worship others with Allah, all that they used to do would have been of no benefit to them.
This magnifies the serious danger of Shirk and the gravity of committing it.
In another Ayah, Allah said;
وَلَقَدْ أُوْحِىَ إِلَيْكَ وَإِلَى الَّذِينَ مِن قَبْلِكَ لَيِنْ أَشْرَكْتَ لَيَحْبَطَنَّ عَمَلُكَ
And indeed it has been revealed to you, as it was to those (Allah's Messengers) before you: "If you join others in worship with Allah, surely your deeds will be in vain." (39:65)
`If' here does not mean that this would ever occur, as is similar in Allah's statement;
قُلْ إِن كَانَ لِلرَّحْمَـنِ وَلَدٌ فَأَنَاْ أَوَّلُ الْعَـبِدِينَ
Say: "If the Most Beneficent had a son, then I am the first of Allah's worshippers." (43:81)
and,
لَوْ أَرَدْنَأ أَن نَّتَّخِذَ لَهْواً لاَّتَّخَذْنَـهُ مِن لَّدُنَّأ إِن كُنَّا فَـعِلِينَ
If We intended to take a pastime (a wife or a son, etc.) We could surely have taken it from Us, if We were going to do (that). (21:17)
and,
لَّوْ أَرَادَ اللَّهُ أَن يَتَّخِذَ وَلَداً لاَّصْطَفَى مِمَّا يَخْلُقُ مَا يَشَأءُ سُبْحَـنَهُ هُوَ اللَّهُ الْوَحِدُ الْقَهَّارُ
If Allah willed to take a son, He could have chosen whom He pleased out of those whom He created. But glory be to Him! He is Allah, the One, the Compelling. (39:4)
Allah said,