I know this is an old question but I'm looking for an answer myself... maybe confirmation of my own theory.
I see no chance of humans developing horns as is. We've evolutionarily invested so much energy into making our brain our primary tool without investing into proper protection - the one we have is enough for the use of our head as main energy and sensory input device. Any advantage horns could theoretically give us would require significant changes to all the surrounding anatomy only to not endanger our brains. And even if you solved this question and equipped our muscles, skeleton, and brain cushioning adequately for functional horns, there's still the open question of their advantage to us. Arms have more reach, more mobility, hands can craft and grab dangerous objects to give even more reach, they're just so far superior, except maybe for stabbing other people, but brains and hands can craft stabby tools. So, if not as a weapon, and ruling out sexual selection, what else could their purpose be?
Looking for a use
If you look at horned creatures, they use all of their limbs for locomotion and they're herbivorous and basically have no other form of protection. Their horns are mostly a tool to discourage predators or used as weapon of self-defense should the attacker try anyways, or fight rivals for reproductive rights. Maybe to dig out roots or other food, but then again, we have hands... and the brains to craft the Bagger 293, try to outdig that one with your puny horns.
Now, considering our own evolutionary ancestry, we once were mostly herbivorous (or fructivorous to be more precise) and led an arboreal lifestyle. Go far enough into the past and our arms become increasingly used as a tool of locomotion and less for manipulation. Our brains were smaller and less important than they are today. So, maybe the ancestors of those horned humans led an exclusively arboreal lifestyle and had an advantage if they were able to use all of their limbs for locomotion, but still had to fight rivals to secure the right to mate. In come horns, not having to use hands as weapon could give them the ability to out-manoeuvre their rivals, but still attack, although probably only under specific circumstances; certainly a stronger neck, maybe also a longer one to increase reach and flexibility. I guess you'd have to go far back in time to make that a somewhat viable explanation. Later on the horns could merely be a remnant without any disadvantage and thus remain in one form or another, maybe over time the useful horns developed into a symbol of sexual selection, then they could remain viable to our horny Homos even when they develop into a detriment - male peafowl feathers have grown so large due to sexual selection, they've actually become a disadvantage when trying to escape a predator.
Our ancestors also grouped up to increase survivability, because they had no anatomic feature to defend themselves against predators - although some can be deterred by a good smack on the snout (sharks can and I think crocodiles, too) but I'd still not recommend trying to punch a lion's nose unless it's your absolute last option and you'd die anyway. A group of weak individuals can more easily overwhelm a stronger attacker than any single one could. It also helped develop our social behaviour; and our brain, finding out on how to work together requires brainpower after all. Maybe only the male (or female for that matter) individuals of the Homo Horniensis ancestors developed horns and roamed the forests solitarily while the other sex grouped up to raise the young and nurture their brains. I'd certainly be glad about a couple of dangerous spikes on my head alone in the woods with predators.
In the end, if you go that far back to make horns a viable option and change all the variables required to do so, what environmental changes would then have to happen to force the hornys into the same evolutionary path we humans took? Take away the trees, okay sure. maybe make their main food source die out and their alternatives harder to reach to force their arms into a path of manipulation > locomotion. In the end though, I guess by that point you'd basically have to make the horns a non-functioning remnant, otherwise evolution would probably solve the obstacles we humans faced in a different fashion and you end up with a baboonicorn or somesuch.
What about spikes instead?
A different idea would be to give them spikes, like hedgehogs or porcupines have. After the forests dwindled and savannahs emerged around Cape Horn (yes, I know there's no savannahs there but there's also no spiky humans), our humans had already evolved bipedal locomotion, maybe even basic tool usage, but due to resource limitations shrunk in size (keyword island dwarfism). Now, large aerial predators hunted the pygmys, swooping down and snatching them up basically grabbing whole heads with their claws. With their heads most exposed and in danger not only helped their hair growing together into thin spikes blend in with the tall and dense grasses from bird perspective, they would also severly hurt the predators should those try to catch one, who didn't see the danger early enough to hide. I've heard porcupine stings hurt like hell, and they can detach and get stuck in your flesh... ouch. A bird certainly needs their feet to land, they can't limp like a quadruped can to releive pain in the affected limb or just lie down on the side. They'd certainly think twice about trying to catch another one of those little spiky human buggers should they get through the injury.
Why the body size changes? Well, basically limitiations on the size of aerial predators. Even the largest birds to date couldn't snatch up a human. The largest extinct bird capable of flight? Argentavis Magnificens with a wingspan of up to 6.5m standing at human height size and weighing about 70kg is thought to have been mostly a scavenger. Pelagornis Sandersi with a wingspan of up to 7.4m but only up to about 40kg is thought to have been mostly a glider flying long distances over oceans and catch fish mid-flight with their "toothed" beaks. The largest bird of prey, the Haast's Eagle grew only up to 15kg with a wingspan of up to only 2.6m; it is presumed to have hunted the giant moa, much larger than a human, though didn't snatch them up. Then again, I guess that is already enough. You could also go wild and say the gravity of their planet is lower or its atmosphere denser and create monstrous flying birds.
What is that, pterosaurs you say? Sure, some of them got much larger but like Pelagornis Sandersi they were gliders and either caught fish during their flight out in the oceans or the largest ones actually hunted on land, stalking the beaches where flocks of smaller pterosaurs nested and just prance about gobbling up any youngling out in the open in front of their terrified parents. Maybe that works, too ...