Evolution doesn't necessarily need the function to exist prior to the mutation.
That being said evolution is a random process, it is the selection which is not. There may well have been a member of an ancestor species which did evolve horns but since there was no advantage to it the mutation didn't persist.
So we need to look at what makes horns useful.
Mating rituals are an example where a species decided to use some aspect of themselves (colourful feathers, large horns, larger vocal range) to give them a better chance of reproducing.
The chance of this evolving is higher where we have competitive intrasexual selection. If there was little else to make a mate stand out horns may become a factor and so grow in size.
To evolve these you want a situation where the imposing size and reach of antlers can be used to hunt. (Though balance is more likely to be a problem if your species is standing upright and has wide spread antlers).
(There are also proposed uses of antlers as a means of clearing snow, but this is of no use to a species with hands).
So really you just need to pick the situation within which the horns or antlers you want are most likely to be used and evolve them within that. I believe horns would be more practical (less likely to lose balance) but neither can be ruled out as impossible.
As a side note: Humans can grow horns but they are believed to be some form of tumor rather than an evolutionary trait.
Many of the great apes have a sagittal crest, which is a ridge running along the skull that allows for stronger attachment of chewing muscles. Male gorillas have particularly large crests, which may be a form of displaying mating fitness in addition to its practical use. It is plausible that in some circumstances, runaway sexual selection may promote larger and more elaborate crests, particularly in males.
However, it is unlikely that simian horns would ever be used for fighting. In ungulates, head-butting is a fairly effective means of attack even without horns, thanks to their high running speed and low positioning of the head while charging. This promotes the evolution of hard plates and sharp protuberances that increase the effectiveness of the head as a weapon. Simians, by contrast, tend to bite, scratch, and strike with their hands while fighting. While a primate in a pinch may employ its head as a weapon, it is unlikely that this would ever become their go-to means of attack.
So if a simian species developed horn-like growths on its head, they would probably be more akin to the crests of birds than the horns of ungulates: sexual displays, not practical weapons. Light weight would be more important than strength. I would expect the bony sagittal crest to remain, but the structures on top would be more lightweight and probably shaped in such a way that would minimize the balance problems they would cause in the trees - wide and flat, rather than tall. These crests would probably be more prominent in more robust apes that tend to live on the ground and fight or scare off predators rather than run away. It is also possible that they would be covered in brightly colored fur to increase their visibility.
As already mentioned antler-like horns or other large up sweeping horns are unlikely in a tree dwelling animal because they will get caught in branches and generally cause trouble.
But what about a single smallish horn on the forehead?
I haven't found any evidence that it is a real life usage but I don't think it's too much of a stretch to say a monkey or ape could use a horn like that to dig at bark high up in trees to unearth insects hidden inside while using it's hands to maintain it's balance.
If it is a larger ape then it could also use the horn to break open small holes in trees where birds might nest to make the holes big enough to reach into and extract eggs or the birds themselves.
A horn of even a few inches could be useful while not impeding anything else and would be a starting point to evolving more impressive headgear further down the line if that is what you are wanting.