Pakistan allows Afghanistan refugees because it has been promoted for decades that Pakistan and Afghanistan are brothers and we are one. The afghan and Pakistan pashtun are relatives, they have 1000s of families on each side so you cannot really stop them from coming or crossing the border. The pashtuns trade with each other etc.
Regarding the Taliban, its a loose organisation with many different groups, we also have many sufis who are aligned to the Taliban, they too have 1000s of fighters. They are certainly not extremists or someone who would promote terrorism in Pakistan because they too faced terrorism in Pakistan loosing 1000s of people (their families and followers in Pakistan were targeted by terrorists).
Pakistan should clearly targeted the extremist takfiri elements in the taliban and the terrorism will decrease automatically. I don't know which side is more powerful, the extremists or the moderate ones. It looks like the taliban themselves cannot control these people. If Pakistan starts to bomb Afghanistan they will end up killing the innocents and moderate taliban also so this will increase the problem. The solution is to support the pro Pakistan elements or the moderate ones, then slowly decrease the power of the extremist takfiris, also support the Tajikistan, Uzbekis, Turks, hazaras, slowly win them over and it will neutralise the anti Pakistan pashtuns.