Satan was originally one of God’s holy angels, but he rebelled against God and was cast out of heaven (Luke 10:18). That was only the first stage of his judgment. Satan’s kingdom was vanquished at the cross (John 12:31–32). Later, he will be bound in the abyss for one thousand years (Revelation 20:1–3) and then will be cast into the lake of fire for eternity (Revelation 20:10).
Until his final judgment, Satan is "the prince of this world" (John 14:30), but it seems that he still has restricted access to the heavenly realms. In Job 1:6, Satan stands in the presence of God. There is a similar situation in 2 Chronicles 18:18–21 involving a "lying spirit."
Since God is holy and absolutely without sin (Isaiah 6:3), and since He will not even look on evil (Habakkuk 1:13), how can Satan be in heaven? The answer involves God’s sovereign restraint of sin. In Job 1, Satan stood before God to give an account of himself. God initiated the meeting, led the proceedings, and remained in absolute control (verse 7). The result was that Satan’s power was limited (verse 12) and God was glorified.
Here are some other facts to note: 1) Satan does not have open access to God’s presence. He is summoned by God. 2) The visits are temporary. His time before God’s throne is limited. 3) In no way is the purity of heaven tainted by the brief, God-ordained presence of a sinful being, "quarantined," as it were, by God’s regulatory power. And, 4) Satan’s access is only granted prior to the final judgment. After the judgment, God creates a new heaven and new earth (Revelation 21:1), wipes away all tears from our eyes (verse 4), reveals the New Jerusalem (verse 10), and promises the complete absence of sin (verse 27).
When we say, "God cannot allow sin into heaven," we simply mean that God cannot allow human beings who are still in their sin to live in His presence. But it is possible for God to command a sinful being to stand (temporarily) in His presence in order to commission him (Isaiah 6), to exact an account from him (Job 1-2), or to judge him (Revelation 20:11–15) without compromising His holiness.
God’s holiness will eventually consume all sin. Until that day, His holiness regulates sin, and that means that Satan, on certain occasions, is briefly summoned before his Creator to give an account of his actions.