a court official: a trusted royal attendant or high officer in a king's service.
This is the word for a man who holds a post inside a royal household or government. He stands close to the throne and carries out the king's business: guarding the palace, overseeing the harem, running an errand of state, commanding troops, or managing the king's affairs. The job, not any physical condition, is what the word names in these places.
The clearest proof that the word can mean simply "officer" is Potiphar, called by this title yet plainly a married man with a household of his own. The same is true of Pharaoh's chief cupbearer and chief baker, of the commander set over Judah's soldiers, and of the various palace officers who appear in the courts of Israel, Judah, Babylon, and Persia. In all of these the word marks rank and royal service.
Because such posts were often filled by castrated men in ancient royal courts, the word also came to mean "eunuch" outright (the second meaning below). Many verses sit between the two: an officer of a foreign king, or a keeper of the women, may or may not have been castrated, and the text does not always say. Where it cannot be settled, the safest reading is the plain one, an officer of the court.