(written from a Production point of view)
Referenced multiple times in behind-the-scenes documentation from the making of Star Trek: The Original Series, Horatio is a character in William Shakespeare's play Hamlet. In that story (but not established in any of the documents related to the making of Star Trek), Horatio is a friend of Prince Hamlet.
Horatio was mentioned once in the final revised draft of the script for "The Conscience of the King" (dated 8 September 1966). The script referred to Horatio as being portrayed by a member of the Karidian Company of Players during a performance of Hamlet aboard the USS Enterprise, in the starship's theater. The actor playing Horatio walked offstage just as Captain James T. Kirk entered the backstage area.
Additionally, a sheet of notes from the development of "The Conscience of the King" (a document dated 15 December 1966) likened Spock to Horatio, observing, "Mister Spock – playing a solemn kind of Horatio – warns against rashness in making any kind of charge unless Kirk is sure," regarding the possibility of Kirk accusing Anton Karidian of actually having been Kodos.
Horatio was also mentioned in the scripts of "The Squire of Gothos" and "Catspaw", both times being mentioned as part of the quote, "There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy." Both instances were analyzed by Kellam de Forest (in research notes dated 26 October 1966 and 24 April 1967, respectively). However, the quote wasn't ultimately used in either of those two installments, and it wasn't until ENT: "Cogenitor" that the quote was used on-screen in Star Trek, though that usage of the quote eliminated the reference to Horatio's name.