God knows about your sin before you know about it. He can prevent it if he chooses. He chooses to allow some sin to happen for a time. In his timing he'll end all sin. God is always in control.
God knows about people who will sin against Him before they do:
Deuteronomy 31:16 And the LORD said unto Moses, Behold, thou shalt sleep with thy fathers; and this people will rise up, and go a whoring after the gods of the strangers of the land, whither they go to be among them, and will forsake me, and break my covenant which I have made with them.
Deuteronomy 31:20 For when I shall have brought them into the land which I sware unto their fathers, that floweth with milk and honey; and they shall have eaten and filled themselves, and waxen fat; then will they turn unto other gods, and serve them, and provoke me, and break my covenant. 21 And it shall come to pass, when many evils and troubles are befallen them, that this song shall testify against them as a witness; for it shall not be forgotten out of the mouths of their seed:
for I know their imagination which they go about, even now, before I have brought them into the land which I sware.
Deuteronomy 31:29 For I know that after my death ye will utterly corrupt yourselves, and turn aside from the way which I have commanded you; and evil will befall you in the latter days; because ye will do evil in the sight of the LORD, to provoke him to anger through the work of your hands.
God prevented Abimelech from sinning:
Genesis 20:6 And God said unto him in a dream, Yea, I know that thou didst this in the integrity of thy heart; for
I also withheld thee from sinning against me: therefore suffered I thee not to touch her.