A truce observed previously between the government of Pakistan and the Taliban leader Sufi Muhammad restricted Taliban to an area in swat and allowed them to make their own sharia courts. Also in this truce in February it was demanded by the Taliban to stop the all kinds of violence and fighting in the area. Also they were told to not move further from the swat.
Soon afterwards the all deals collapsed between the Government and the Taliban leader, and militants started moving in to neighboring districts in the month of April. At same time a military offensive was also launched to stop these militants from moving further into the other areas and eliminate any groups who were actually working against the countries interests and were harming the local citizen of those effected areas.
It was required by this Taliban leader that he keep all his promises and keep everybody safe. But when he was unable to do that and started speaking against the country and in favour of terrorism meanwhile trying to impose his own customised version of Sharia, it was required to stop him. So finally going few months into the military offensive the military was able to arrest the Sufi Muhammad.