The short answer, is that works are not a requirement of salvation, but are an indication of salvation through faith, and the Holy Spirit working within the heart of the saved person. As such, the virgins in the parable that were not prepared were not of faith, as indicated by their surprise at the arrival of the bridegroom. Keep in mind that this parable is in reference to the second coming of Christ.
This interpretation is largely supported by the idea that the virgins were "foolish", as opposed to forgetful in failing to bring enough oil to wait until night, which demonstrates a lack of faith on their part that the bridegroom would arrive at all.
Also important is verse 25:11 of Matthew (ESV):
"Afterward the other virgins came also, saying, 'Lord, lord, open to us.'
But he answered, 'Truly, I say to you, I do not know you.'"
Note that he does not say that they were not prepared or had not done enough to merit entry, but that he did not know them at all, a phrase used by Jesus to indicate non-believers, such as the Pharisees in John 8:19 (ESV):
"They said to him therefore, "Where is your Father?" Jesus answered, "You know neither me nor my Father. If you knew me, you would know my Father also." The Pharisees knew Jesus' identity, of course. He was speaking to knowledge of him as the Son of God.
The comments above are my interpretations. The following additional response is taken largely from the interpretations presented in the HCSB Study Bible, specifically Charles Quarrels of Louisiana College, who authored the commentary on Matthew.
In the HCSB commentary, the virgins represent those who fail to persevere by waiting for Jesus' return with constant vigilance. The cry of "Master, master" (Gk kurie, kurie ) is identical to that of the false disciples in Matthew 7:21 . "I do not know you" echoes Matthew 7:23 and expresses exclusion from Messiah's kingdom.
The parable does not describe a true disciple who loses his salvation, but a false one whose commitment to Jesus was deficient from the start.