Probably the main factor is counter-narcotics and the revenue that it brings, but also the fact that Pakistan has been at least tacitly allowing for activities to develop in certain regions.
I'm not a specialist regarding Pakistan's case, but I can tell you it is very complicated. You have different regions with different realities. Some of these regions on the border are controlled by Islamist powers, and the Pakistani army has been trying to put down these movements. Having a refuge has helped the Taliban and different extremists—al-Qaeda and so on—tremendously to regroup, rearm, and reorganize. You have a group with a refuge, training camps, and money. In the long run, that delivers the results we see today.