Please read sakhi below to know why it was built.
Guru Gobind Singh ji had made up his mind to fight the autocrats (enemies) with sword. So, he was enlisting the new recruits in his army every day. Guruji realized that without a drum (Nagaar) military equipment was incomplete. He called Diwan Nand Chand and ordered him for the construction of a big Nagaara.
But in those days only kings could beat a drum in their own kingdom. No king would allow another king to march through his area with the beat a drum in their own kingdom. No king would allow another king to march through his area with the beat of drum.
But Guruji’s mother Mata Gujriji advised him to devote himself to religious affairs only. After hearing mother’s advice calmly, Guruji said, “My dear mother, my religion and religion of my forefathers inspired me to take up arms. I tell you what I am doing; I am doing according to the will of God. Almighty had send me in this world to up root the tyrants and uplift the down trodden. Now I will not sit in seclusion. Now I must accomplish the mission of Guru Nanak.
According to wish of God, Tyrants have to be disarmed and evils achievers have to be destroyed. I am not afraid of hill-chiefs. I bear them no malice and I have to be destroyed. I am not afraid of hill-chiefs. I bear them no malice and I have done them no harm.” At last in 1684, Guru Gobind Singh had a special drum prepared. It was named Ranjit (the winner of the battle-field). This drum was beaten at the Keshgarh Sahib throne, at Anandpur Sahib, every day, as a declaration of the sovereignty of the Khalsa (pure ones). Guru Sahib made it obligatory that before the closing of the Gurdwara, the beating of the Nagara was mandatory. The Nagara is a symbol of the sovereignty of truth and righteousness. Only the winner of a battle could beat it. Nishan (flag) and Nagara (drum) are an integral part of a Takht (Khalsa Throne) and all the Gurdwaras.