I think there's pretty good evidence that the ISI has (does?) financed/organized training camps for anti India groups (like Lashkar-e-Taiba) in Afghanistan.
1) Fear of Indian sponsored proxies and being squeezed from both sides. An India friendly Afghanistan presents an existential danger to Pakistan's interests. Pakistan does not want to be encircled by hostile powers.
2) An unstable Afghanistan means possible anti-Pakistan elements taking root. Better to sponsor known "pakistan friendly" elements like the Taliban instead of unknowns.
3) Defense in depth. Pakistani military and political doctrine would use Afghanistan as a redoubt. Most of Pakistan is extremely flat until you get to the Hindu Kush/Pamir mountains. The idea would be, let India steamroll the flat lands, retreat into the mountains and cross the durand line, coordinate the response from Afghanistan.
Pakistan is between Afghanistan and India. https://www.atlapedia.com/online/maps/political/Afghan_etc.h... I'm confused as to how it would be a buffer. Can you explain?