Either I misunderstood your scenario, which I apologize, or I didn't find the connection to when/how a contract is acquired when I researched this topic. You asked the same thing at the start of free agency, and I was genuinely interested so I went down a rabbit hole, I thought that this was the best source that I found in that search but it was not complete. As I understand the rule, if a team has a player whose contract expires, and they sign with another team prior to the draft, the team that lost the player is eligible for compensation. Then there is a formula based on average value per year, playing time, etc. Also you cancel out your compensation when you sign a player eligible for compensation and each team has a max of 4 comp picks.
I also found an article that said that Joseph and Suh would have been eligible for compensation had another team signed them to a lucrative deal this offseason (which was never going to happen - but interesting that they were eligible) - granted those were mid-season free agent signings not mid-season trade pickups. If you find a source that confirms the compensation cut-off for a player acquired in a trade please post, i'm generally interested in the details because its difficult to find the details.
I think there are multiple reasons a team like Detroit would trade a player in the last year of the contract rather than wait for a comp pick, including:
1) as you pointed out, they acquire a 4th which is higher than they would receive if Swift gets comped on his next contract
2) if the lions are active in the next free agency and sign more comp eligible players than they lose, they will receive no compensation even if they lost swift. So trading to a less active team potentially allows both to be rewarded rather than nobody
3) opens a roster spot instead of holding onto a player that was not going to get the ball enough to justify a roster spot