It wouldn't have been that difficult for Jon to find out what happened in King's Landing. Stannis's men were at Castle Black around that time, so it's entirely possible that Stannis, Davos, or Melisandre told Jon about the events surrounding Ned Stark's execution, including Janos Slynt's role in the betrayal.
Alternatively, Slynt himself might have told other members of the Night's Watch about his days as commander of the City Watch, since he loved boasting about his former position. It's entirely plausible that Jon eventually learned about his role in Ned's betrayal through those conversations, especially since Slynt had a habit of bragging about his past.
Honestly, I’ve always felt that Jon might have deliberately baited Slynt into reacting with anger and defiance by ordering him to take command of the ruined Greyguard. Slynt took the bait, openly disobeyed Jon, and ended up getting executed. Exactly what Jon might have wanted..
If this theory is correct, it would be a pretty dark form of poetic justice. Jon would have used his authority as Lord Commander to get revenge for his father while making Slynt’s own insubordination the official reason for his execution. And honestly, I don’t think many people would blame Jon or think less of him for wanting to see that son of a bitch dead.