From his commentary on Acts 2:47:
Therefore it does not follow that, because God can do all things, therefore he must do all things. God is omniscient, and can know all things; but does it follow from this that he must know all things? Is he not as free in the volitions of his wisdom, as he is in the volitions of his power? The contingent as absolute, or the absolute as contingent? God has ordained some things as absolutely certain; these he knows as absolutely certain. He has ordained other things as contingent; these he knows as contingent. It would be absurd to say that he foreknows a thing as only contingent which he has made absolutely certain. And it would be as absurd to say that he foreknows a thing to be absolutely certain which in his own eternal counsel he has made contingent.
By absolutely certain, I mean a thing which must be, in that order, time, place, and form in which Divine wisdom has ordained it to be; and that it can be no otherwise than this infinite counsel has ordained. By contingent, I mean such things as the infinite wisdom of God has thought proper to poise on the possibility of being or not being, leaving it to the will of intelligent beings to turn the scale. Or, contingencies are such possibilities, amid the succession of events, as the infinite wisdom of God has left to the will of intelligent beings to determine whether any such event shall take place or not. To deny this would involve the most palpable contradictions, and the most monstrous absurdities.
If there be no such things as contingencies in the world, then every thing is fixed and determined by an unalterable decree and purpose of God; and not only all free agency is destroyed, but all agency of every kind, except that of the Creator himself; for on this ground God is the only operator, either in time or eternity: all created beings are only instruments, and do nothing but as impelled and acted upon by this almighty and sole Agent.
Consequently, every act is his own; for if he have purposed them all as absolutely certain, having nothing contingent in them, then he has ordained them to be so; and if no contingency, then no free agency, and God alone is the sole actor. Hence the blasphemous, though, from the premises, fair conclusion, that God is the author of all the evil and sin that are in the world; and hence follows that absurdity, that, as God can do nothing that is wrong, Whatever Is, is Right. Sin is no more sin; a vicious human action is no crime, if God have decreed it, and by his foreknowledge and will impelled the creature to act it. On this ground there can be no punishment for delinquencies; for if every thing be done as God has predetermined, and his determinations must necessarily be all right, then neither the instrument nor the agent has done wrong.
Thus all vice and virtue, praise and blame, merit and demerit, guilt and innocence, are at once confounded, and all distinctions of this kind confounded with them. Now, allowing the doctrine of the contingency of human actions, (and it must be allowed in order to shun the above absurdities and blasphemies), then we see every intelligent creature accountable for its own works, and for the use it makes of the power with which God has endued it; and, to grant all this consistently, we must also grant that God foresees nothing as absolutely and inevitably certain which he has made contingent; and, because he has designed it to be contingent, therefore he cannot know it as absolutely and inevitably certain.
I conclude that God, although omniscient, is not obliged, in consequence of this, to know all that he can know; no more than he is obliged, because he is omnipotent, to do all that he can do.