Allegory and Allegorical Interpretation
Allegorical interpretations of the Bible have been rightly downplayed since the Reformation. The idea that all of Scripture says one thing but that you can derive a deeper spiritual meaning may come from a place of piety. But often times allegorical interpretation clouds the meaning of the Bible. And it's unnecessary to understand spiritual truth because the historical meaning of the Bible is spiritual. But, while we rightly downplay allegorical interpretation, let's not shy away from reading passages in the Bible which are allegorical. There is a difference between an allegorical interpretation (the way you read the Bible) and the genre of allegory.
Allegorical Interpretation
Allegorical interpretation means that you see the literal meaning of a story as a sign that points to a deeper reality, namely, some spiritual or christological truth. One early Christian interpreter explained away God's command of destroying the Canaanites by using just such an interpretation. Origen argued that the conquest of the Canaanites signified Jesus conquering our sins. To my mind, this is unsatisfying because it divests the historical meaning of the Bible of its meaning. But that historical sense is how the Bible came to us. God led people across time and history to write inspired texts. So, let's be sure to give attention to the historical meaning of these texts. But this doesn't mean that there are no allegories in the Bible. What do you do with texts that are allegories? How do you literally read them?
Allegories
Hosea literally marries Gomer. But Gomer's unfaithfulness to Hosea signifies Israel's disobedience to God. In this case, Hosea is a prophet, Gomer an unfaithful wife. But the prophet points to God, the wife points to Israel. It is an allegory. You don't need to use allegorical hermeneutics (described above) to read the text this way. It's the surface meaning of the text. Ezekiel sees dry bones that come to life. He sees bones which signify the people of Israel being spiritually enlivened. It is an allegory (or perhaps a prophetic vision is better here?). So, while the Bible does not have a large number of allegories, they exist. And you can see them by reading them literally.
So What Is Paul Doing in Galatians 4?
For it is written that Abraham had two sons, one by a slave woman and one by a free woman. But the son of the slave was born according to the flesh, while the son of the free woman was born through promise. Now this may be interpreted allegorically: these women are two covenants. One is from Mount Sinai, bearing children for slavery; she is Hagar. Now Hagar is Mount Sinai in Arabia; she corresponds to the present Jerusalem, for she is in slavery with her children. But the Jerusalem above is free, and she is our mother. - Galatians 4:22–26
Paul reads the story of Sarah and Hagar allegorically. Some might suggest that Paul is simply reading the text typologically, meaning that he sees these two women as prefiguring later realities. If that were the case, I suspect Paul would have said so. Instead, he says that the story has an allegorical meaning (allegoroumena). So what do we do with Paul? I have argued that allegorical interpretation is unhelpful, whereas reading the Bible literally is beneficial---while allowing texts to be allegories in terms of their literary genre. But what is Paul doing? Paul is not quite reading the text typologically, but he is definitely using typological logic. He reads the Bible as a story that progressively points to and leads up to Christ (and all that Christ's work entails). There is a real sense, then, that realities in the Old Testament correspond to later truths. The temple points to Christ who fulfills its purpose through his body, the church. The Passover lamb corresponds to Christ. And so on. For Paul, this validates reading the Old Testament as Christian literature. And that kind of logic seems to be what grounds his allegorical reading of Genesis. Paul makes a crucial theological point by allegorically reading Genesis. The freedom of Sarah allegorically refers to those who belong to the heavenly Jerusalem, which sets its inhabitants free by the Gospel; the slave Hagar corresponds to the earthly Jerusalem, which is still under the law of Moses and so enslaved. So it's valid to read the Bible allegorically when that allegory fits into the storyline of the Bible. But this is the only instance in the New Testament where someone explicitly interprets the Old Testament while calling it allegorical. It's an exception to the norm, and we should follow suit and only use allegory to, in the language of Thomas Schreiner, "startle the readers, so that they will see the truth of his gospel from a different angle" (Galatians, 2010: 300). In short, Paul used the allegory to startle his readers to underscore the truth of the Gospel. It was exceptional and that is why it could make the point. Were it his usual manner of interpretation, it would no longer be exceptional and would lose its force.
Conclusion
Read the Bible literally. But don't let that literal reading prejudice you against seeing allegories within the Bible. And while it might be permissible to occasionally make a point by using allegory like Paul did. This should be the exception, not the rule.