You are conflating two different things. Legality under international law and might is right.
When it comes to Afghanistan and KP, Pakistan has both international law and the military might in its favor, so the anti-Pakistan Afghans can stick to whining, crying and begging India & the US to help them against Pakistan.
On the subject of J&K, Pakistan’s position is supported by the UNSC resolutions but militarily neither India nor Pakistan can currently change the status quo.
With respect to Shaksgam, you’re completely wrong and need to read the following thread - Pakistan gained territory, it did not cede territory to China.
Did Pakistan cede Kashmiri Territory of Shaksgam valley to China? Debunking propaganda from a laymen's perspective Myth: Pakistan ceded the Trans-Karakoram tract or Shaksgam valley to China in the Trans-Karakoram pact thus showing utter disregard for Kashmiri sovereignty or its own sovereignty...
defence.pk