All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ʻalayhi wa sallam, is His slave and Messenger.
There is no contradiction at all between these two verses (praise Allaah!). In fact, they both derive from the same source and point to the doctrine of the Ahl As-Sunnah wal-Jamaa‘ah concerning the Qadar (predetermination), which includes affirmation of human action, will, choice and faculty by which one's actions occur, and because of which one is either rewarded or punished on the basis of this will and choice. And on the other hand, the doctrine of Qadar includes affirmation of Allaah's preceding will, which nothing escapes, not even the smallest particle in the universe.
Thus Allaah's words (which mean) {Indeed, they had taken the devils as allies instead of Allaah} [Quran 7:30] point to the affirmedness of their actions, which occur by their will and choice, and because of which their judgment in the hereafter occurs. However, this action of theirs occurs by the all-powerful Will of Allaah. Thus, they do not do anything by forcing Him (Allaah forbid!). His words in the preceding verse point to this: {Indeed, We have made the devils allies to those who do not believe.} [Quran 7:27] These two verses are similar to the verse (which means): {For whoever wills among you to take a right course. And you do not will except that Allaah wills – Lord of the worlds.} [Quran 81:28-29]
Also, Allaah is a just Judge, Who by His wisdom puts things in the right places, and so he does not pair these people with the devils and make them their allies except after they prefer blindness to guidance and the immediate to the everlasting, and except after they choose error over reason, as Allaah says (what means): {And when they deviated, Allaah caused their hearts to deviate.} [Quran 61:5] Thus Allaah repays them for their actions in kind and proportion.
What we have summarized here concerning the agreement of these two verses has been expounded upon in the works of the scholars, which explain the doctrine of Ahl As-Sunnah concerning the Qadar. We advise you to refer to Dr. ‘Umar Al-Ashqar's book on Qadar, which is part of a his series on 'Aqeedah (doctrine), as it is of immense benefit.
Allaah Knows best.