The gates of horn and ivory are a literary image used to distinguish true dreams (corresponding to factual occurrences) from false. The phrase originated in the Greek language, in which the word for "horn" is similar to that for "fulfill" and the word for "ivory" is similar to that for "deceive". On the basis of that play on words, true dreams are spoken of as coming through the gates of horn, false dreams as coming through those of ivory.

The Odyssey
The earliest appearance of the image is in the Odyssey, book 19, lines 560–569. There Penelope, who has had a dream that seems to signify that her husband Odysseus is about to return, expresses by a play on words her conviction that the dream is false. She says:
Stranger, dreams verily are baffling and unclear of meaning, and in no wise do they find fulfillment in all things for men. For two are the gates of shadowy dreams, and one is fashioned of horn and one of ivory. Those dreams that pass through the gate of sawn ivory deceive men, bringing words that find no fulfillment. But those that come forth through the gate of polished horn bring true issues to pass, when any mortal sees them. But in my case it was not from thence, methinks, that my strange dream came.

Arthur T. Murray, translator of the original Loeb Classical Library edition of the Odyssey, commented:
The play upon the words κέρας, "horn", and κραίνω, "fulfill", and upon ἐλέφας, "ivory", and ἐλεφαίρομαι, "deceive", cannot be preserved in English.

Echoes in later Greek literature
Homer greatly influenced Greek literature as a whole.  Plato refers to the two gates in his dialogue Charmides:
Socrates: "Listen then," I said, "to my dream, to see whether it comes through horn or through ivory."
A reference to the Odyssean image also appears in the late (c. AD 400) epic poet Nonnus:
As Morrheus slept, the vision of a dream cajoled him,
beguiling his mind after flitting through the gates of ivory.

The Aeneid
Virgil borrowed the image of the two gates in lines 893–898 of Book 6 of his Aeneid, describing that of horn as the passageway for true shadows and that of ivory as that through which the Manes in the underworld send false dreams up to the living. Through the latter gate Virgil makes his hero Aeneas, accompanied by the Cumaean Sibyl, return from his visit to the underworld, where he has met, among others, his dead father Anchises: 
Two gates the silent house of Sleep adorn;
Of polish'd ivory this, that of transparent horn:
True visions thro' transparent horn arise;
Thro' polish'd ivory pass deluding lies.
Of various things discoursing as he pass'd,
Anchises hither bends his steps at last.
Then, thro' the gate of iv'ry, he dismiss'd
His valiant offspring and divining guest.

Why Virgil has Aeneas return through the ivory gate (whence pass deluding lies) and not through that of horn is uncertain. One theory is that it refers to the time of night at which he returned. Jorge Luis Borges accepted the view that, for Virgil, what we call reality is not in fact such; that Virgil may have considered the Platonic world of the archetypes to be the real world.

Another explanation is that Virgil is thus indicating that what he has recounted is not to be taken as literal fact. In John Wesley's last sermon, preached on 17 January 1791, he spoke of how uncertain even the best conjectures about the invisible world were without revelation: "The most finished of all these accounts, is that of the great Roman poet. Where observe how warily he begins, with that apologetic preface, – Sit mihi fas audita loqui – 'May I be allowed to tell what I have heard'. And, in the conclusion, lest anyone should imagine he believed any of these accounts, he sends the relater of them out of hades by the ivory gate, through which, he had just informed us, that only dreams and shadows pass, – a very plain intimation, that all which has gone before, is to be looked upon as a dream!"

Other Latin writing
In his Silvae V iii 285–290, a lament for his dead father, the poet Publius Papinius Statius, expresses the wish that his father may come to him from the abode of the dead in the form of a true dream, passing therefore through the gate of horn:
Thence mayst thou pass to where the better gate of horn o'ercomes the envious ivory, and in the semblance of a dream teach me what thou wert wont to teach.

In his Cupid Crucified (line 103, the last line of the poem), 4th century AD Latin poet Ausonius says that Cupid escapes through the gate of ivory (portaque evadit eburna), thus implying that the whole scene of the crucifixion of Cupid was a false dream.

The 15th-century Latin poet Basinio of Parma, employed at the court of Sigismondo Malatesta in Rimini, wrote a panegyric epic poem for his prince, titled Hesperis, modelled largely on the Aeneid and the Homeric epics, in which Sigismondo, as epic hero, undertakes a journey to the underworld in order to meet his deceased father Pandolfo Malatesta. Before that he passes the temple of Fama which has a bipartite gate — one half made of horn, one half of ivory. On the ivory half are depicted not only Sigismondo's descent but also those of Hercules, Theseus, Ulysses, and Aeneas.
"Having seen that, they turn towards the astounding temple of Fame, a temple enormous and imposing in size and shape, whose door on its left side is white from ivory steps with shining horn on the other half. Disturbing nightmares are conveyed by false rumour on the vain gates of ivory, while true dreams of horn are sent by trustworthy rumours. The gate of horn shows the Spaniards defeated on the Tyrrhenian shore [i.e. Sigismondo's victory over Alfonso V's troops at Piombino in 1448]. On the ivory steps Sigismondo turns toward the sea, and is swimming after his ship is destroyed [on his way to the island where he is to undertake his trip to the underworld]. There Theseus and also Hercules made their way: there brave and victorious Ulysses went to the gloomy homes of the Cimmerians; there faithful Aeneas took to the Stygian lake Avernus."

English writing
The gates of horn and ivory appear in the following notable English written works:
David Gemmell's epic novel "Troy: Lord of the Silver Bow", chapter sixteen. This is referenced when Odysseus talks to Xander about his vision of the future, and what his wife Penelope had taught him about dreams and their gates in the past on page 268.
Edmund Spenser's epic poem "The Faery Queene" (1590, English) in book 1, stanzas XL and XLIV, in reference to a false dream being brought to the hero (Prince Arthur/the Knight of the Red Crosse).
Alexander Pope's mock-epic The Dunciad (1743), in Book III: "And thro' the Iv'ry Gate the Vision flies."
E. R. Eddison's romance The Worm Ouroboros (1922), in Chapter 2: "...belike the dream was a true dream, sent thee through the gate of horn".
E. M. Forster's short story The Other Side of the Hedge. The reference from Forster comes when the main character of the story observes the two gates; The Other Side of the Hedge is usually read as a metaphor of death and Heaven.
A. A. Milne's three-act play "The Ivory Door" is a condemnation of religious dogma and false belief.
T.S. Eliot's poem "Sweeney Among the Nightingales". The line "And Sweeney guards the horned gate" is likewise a reference to this image.
Eliot's poem Ash-Wednesday. The lines "And the blind eye creates / The empty forms between the ivory gates" similarly refer to this concept.
William Empson's poem 'Letter III': '...offspring of Heaven first born, | Earth's terra firma, the Hell-Gate of Horn'
H. P. Lovecraft's short story "Celephaïs" alludes to the gates of ivory as the portal through which children see the world of wonder, which their adult minds, made wise and unhappy by knowledge of the real world, will reject as fanciful.
Ursula K. Le Guin's novel A Wizard of Earthsea.
Robert Holdstock's novel Gate of Ivory, Gate of Horn.  In the Holdstock novel, the main character grapples with a traumatic event that has two very different manifestations, one true and one false.
Derek Mahon's poem "Homage to Malcolm Lowry". "Lighting-blind, you, tempest-torn / At the poles of our condition, did not confuse / The Gates of Ivory with the Gates of Horn."
Margaret Drabble's novel The Gates of Ivory
W.H. Auden's poem "Prime" in Horae Canonicae.
Seamus Heaney's poem "To a Dutch Potter in Ireland" in The Spirit Level (poetry): "Then I entered a strongroom of vocabulary / Where words like urns that had come through the fire / Stood in their bone-dry alcoves next a kiln // And came away changed, like the guard who'd seen / The stone move in a diamond-blaze of air / Or the gates of horn behind the gates of clay."
Lord Dunsany's poem "The Gate of Horn" appears in his 1940 book "War Poems". It is about his leaving his native Ireland and its false dream of neutrality in WW2 to volunteer in Kent to fight the Germans if they invade, and the hope of a true dream of victory.
The Ivory Gate, a novel by Walter Besant, describing a solicitor with a split personality. The utopian thoughts of his alter ego are said to occur "before the Ivory Gate".
Frank Bidart's long poem, "The First Hour of the Night" makes use of both the gates of ivory and horn to question certainty in fact and memory.
The gates are also depicted as part of the Dream world in the graphic novel "The Sandman" by Neil Gaiman

Music
 American progressive metal band Fates Warning's The Ivory Gate of Dreams, a 22-minute-long song on their album No Exit (1988).
 In 2015, Canadian melodic death metal/metalcore band The Agonist released the video for the song called "Gates of Horn and Ivory", as the first single from their upcoming record Eye of Providence.

Software
 The neural-net library Keras, developed as part of project ONEIROS, is named in reference to the gate of horn (κέρας).

References

Fantasy tropes
Metaphors
Odyssey
Aeneid
Fictional gates