In the movie Horns, horns mysteriously popped out of Ig's head, how did it happened? Does the book explain how he got his horns?
There is no specific answer to your question that I can locate. It is possible that Joe Hill's intent (the author of the book) was to reference biblical mentions, as many of the references in the film (and likely the book, as well) are from the Bible. Psalm 75:10 reads:
"I will cut off the horns of all the wicked, but the horns of the righteous will be lifted up."
Another mention appears in Deuteronomy 33:17 as follows:
"In majesty he is like a firstborn bull; his horns are the horns of a wild ox. With them he will gore the nations, even those at the ends of the earth."
It is clear that not all references to horned people indicate evil, but virility and power and righteousness. There are no references anywhere that I can find that suggest people were granted horns and the power to compel others to tell the truth, however. In this, the tale is more like a modern fairy tale, albeit a more adult-oriented one. There are additional references to the Bible noted at IMDB.
Even in the movie, the reason for his horns is a result of his act, punishment for something he did. What he did was, after everyone left the place where his gf died, he broke the statue of Mary and peed on it (very bad). That is why he grows horns because it was his punishment to become evil and to spread evil around him since he himself committed and evil act.
He gets the horns bc (as it is revealed in the end of the novel) he follows the directions left inside the treehouse. They said to take what you Want while you're there and to get what you need as you leave. He then declares that what he needs is to kill Merrin's murderer. Right after this is when Ig's head starts to tingle where the horns will appear the next morning. Although it seems as though the horns are a punishment throughout the novel, they actually end up being the means to the end Ig is trying to achieve. He uses the horns to determine who is the murderer as well as to deliver the fatal wound.
The actual meaning of horns was his pain and suffering which he past after his girlfriend's death. Its a clear metaphor as in the end he doesn't want to kill the original killer which implies that he can't kill him even under the satanic version which implies the bible verse mentioned above:
"I will cut off the horns of all the wicked, but the horns of the righteous will be lifted up." Psalm 75:10