John 1.29It's a puzzling expression because the animal used in the Day of Atonement rituals (Leviticus 16), the sacrifice to "take away sins," wasn't a lamb but a goat (two goats, actually). If John was trying to describe Jesus as being an atoning sacrifice for sins he should have said, "Behold, the goat of God who takes away the sins of the world!"
The next day he saw Jesus coming toward him, and said, “Behold, the Lamb of God, who takes away the sin of the world!"
So, did John get the animal wrong?
The reference to the "lamb" isn't a reference to atonement (Leviticus 16) but to the Passover, where a lamb was killed and eaten in the Passover meal. To be sure, the Angel of Death passes over Israel when it see the blood of the lamb on the doorposts of Israel. But that Passover blood isn't a sacrifice of atonement that "takes away" sins.
So, again, did John get this wrong, mixing up the Passover with the Day of Atonement?
No, what seems to be going on is an intentional conflation of Passover with the Day of Atonement. As N.T. Wright points out, Israel's original exile in Egypt did not come about as a consequence of Israel's sinfulness. Thus, it's true that atonement wasn't originally a part of the Passover motif.
However, Israel's subsequent exiles after the Assyrian and Babylonian conquests were a punishment for Israel's sins. Thus, the end of exile, requiring a second Passover with a second Moses, became necessarily tied up with the forgiveness of Israel's sins, Day of Atonement themes.
In short, by the time of Jesus the Passover and the Day of Atonement, while initially separate, had become intimately linked, the end of exile associated with the forgiveness of sins. And there's no better example of that conflation than John surprising you with a lamb instead of a goat:
“Behold, the Lamb of God [Passover], who takes away the sin of the world [Day of Atonement]!"