George RR Martin's A Song of Ice and Fire has no shortage of gore. The presence of eunuchs in the saga draws from historical records of royal courts and crimes of war. In ASOIAF the first eunuch the reader is introduced to is Lord Varys - a powerful spymaster; he is a self made man who has risen from the penury to a place in the King's council. Ned Stark interacts with him with caution and his approach reflects a hint of contempt and disdain along with wariness - which is in keeping with Ned's traditional and binary views. Tywin Lannister sees more value in Varys and keeps his personal views (also fiercely traditional) to himself.
Like the court eunuchs of history Varys plays a powerful role in the capital. Eunuchs at court were considered harmless. They had no dynastic motivations of their own. They were dispensable having no progeny to avenge them. They had no loyalties to any civil or military institution. The majority of eunuchs were slaves and servants attending to the king's harem, his bedroom and bath, his messages and other menial services. This physical access and proximity to the king often gave the impression that they were influential and had the king's ear. Varys doesn't have any special access to the kings of Westeros. He is at best part of their inner council and superficially a team player, he weaves his plots for the 'good of the realm' and his loyalty is not to any one sovereign but to the crown and subjects.
Varys' position as spymaster (instead of the traditional role of court eunuch) can be compared to Zheng He who was a 15th century admiral in China's early Ming dynasty. Zheng He was a descendant of a governor of the Mongol Empire. He was taken prisoner at a young age by the Ming army and castrated; he gained the admiration of his captor and rose to become of favorite of the emperor who conferred upon him the adopted surname of Zheng. Other influential court eunuchs were those in the Ptolemic dynasties of ancient Egypt who served as regents to underage kings and Bagoas of Alexander the Great's court in Macedonia. 15th century Imperial China had its own eunuch spymaster in Shang Ming in the court of Emperor Chenghua. However his involvement in espionage is probably an exception as few eunuchs were assigned as spies, though they were widely alleged to be involved in espionage. Most of the use of court eunuchs in Imperial China mirrors the bureaucratic work assigned to celibate clerics of the Middle Ages in Europe.
In George RR Martin's saga the castration of Theon Greyjoy is assumed, at the hands of Ramsay Bolton as a method of torture rather than punishment for crimes. Castration was punishment for crimes of homosexuality among the Assyrians and it was one of the the Five Punishments for crimes like rape around the time of the Qin Dynasty. Theon is psychologically tormented and broken down after his capture by Ramsay Bolton for Ramsay's own sadistic pleasures. Castration as a means of punishment doesn't seem to have any official role is the kingdoms of Westeros, but seems common practice across the Narrow Sea in Essos.
The unsullied are the most professional mercenary army in ASOIAF (followed closely by the Golden Company and far ahead of the Second Sons); their soldiers are gelded at a young age and trained as soulless fighters. For them their master's command is law and they have no moral compass, individuality or empathy to challenge it. Historically Chinese prisoners captured by the Vietnamese army in the 15th century were castrated and used as soldiers in the Vietnamese military. In nature the Unsullied mirror ants who are the most battle-ready and aggressive animals; ant warfare is conducted by specialized warriors who have no capacity for reproduction and loss of soldiers in the course of war doesn't threaten the population of the colony.
1. A Game of Thrones - George RR Martin
2. A Clash of Kings - George RR Martin
3. A Storm of Swords - George RR Martin
4. The Eunuchs in the Ming Dynasty - Shih-shan Henry Tsai
5. Strategy - Lawrence Freedman