The conventional wisdom has usually been that these two parshiyos are essentially about tzaraas.
The conventional wisdom has usually been that tzaraas and the attendant isolation and series of rituals designed to bring the leper back into the machaneh were mida kneged mida for lashon hara, if by degree: the negative talk had served to drive people away from each other, hence the speaker experiences this form of internal exile.
In other terms, the speaker made achdus difficult, if not impossible; therefore a form of “yichud” with oneself was the prescribed corrective.
Or was it just for that?
Julius Preuss in his 1911 classic Biblical and Talmudic Medicine lists—based on Arachin 16a, Yalkut 563, and Sanhedrin 107a—fourteen sins that lead to leprosy; but he reserves special mention for “lewdness”, giving David haMelech as the example from Sanhedrin. [Preuss mentions Vashti’s leprosy as payback for making Jewish girls undress, pace Megillah 12b.]
In David haMelech’s case, while the tzaraas was one of the punishments Natan prophesied would be the result of his taking of Batsheva, there might have been another indirect payback by several degrees: the maaseh of Amnon and Tamar and the concomitant issuance of the gezerah of yichud with a penuyah that resulted.
If one reads Sandra Rapaport’s Biblical Seductions [as I did over Pesach] and gets the idea that Amnon icked up his predatory habits from his father—as she at least intimates there might be a hava amian for—you might wonder if, after David himself had unwittingly sent Tamar into Amnon’s lair to meet her fate and he was grappling for a response to a whirlwind of family tragedy [Rapaport does draw a parallel between David taking Batsheva and sending Tamar off—both the result of royal privilege]. So one might think that the gezerah was completely reactive, and punitive to the victims: “If such a great disgrace can occur even to the king's daughter, and all the more so to regular women” [Sanh. 21b].
If one looks at that statement again in light of what had happened, it might not be the case. First one must remember—no matter how it seems like a whitewash—women in those days needed protection [and, after reading Rapaport, the royal women needed it especially.] Second: if yichud is punitive, then it “punishes” everyone—but it especially punishes [or protects?] the men who want access, like Amnon, who would stop at nothing to get it.
So why the gezera on penuyot and not siblings?
My mara d’asra, R. Allen Schwartz, had an interesting theory about Yonadav. Despite the gemara there saying he was a “chacham for evil”, R Schwartz theorized that his entire plan to get Tamar into Amnon’s quarters and have her minister to her might have been to help Amnon get over his obsession—to see her as his sister, taking care of him as a sister would. But it backfired: a man with Amnon’s character could turn the most benign action into something completely inappropriate; a man who would obsess over his sister might eventually obsess over his mother.
[And if the incident hadn’t rendered Amnon impotent—as the gemara notes—he might not have stopped with this incident. One wonders if this could have been another punishment by degrees: as a kerus shafcha, Amnon’s procreative options were now severely—nichras. Which could not have been very flattering to the Crown Prince, who now had to live with a reminder of his criminal act for the rest of his life—which he had to spend in a sort of “yichud”.]
So all the circumstances of Amnon's crime were unlikely to repeat themselves in a situation where there shouldn't have been any kind of sexual miasma. Other situations that lend themselves to that--this might have been the tipoff, however different it was from a "normal" course of events.
The gezera was to prevent a situation where there wouldn’t be a third party to possibly stop the proceedings; the palace incident might have called for a whole different set of safeguards. Which is why—as counterintuitive as it was—the gezera made sense as a response to this incident.
Obviously this didn’t really help Tamar [Rapaport does try to imagine how she might have attempted to cope and rebuild her life]. And one probably won’t find satisfactory answers.
But one can learn three things from the crossover—however limited—between tzaraas and yichud.
The first: EVERYONE has an obligation to behave equally. The onus is on BOTH genders. No one has illicit access to the other.
The second: as much as one might consider Torah and mida kneged mida a “behavior plan” of sorts, it’s never that simple [certainly, it’s not Pavlovian or ABA]. The prescribed correctives may not always seem to directly match the offense. But somehow things seem to eventually add up. [Gehazi, one of the more famous lepers in Tanach, was also one of the Talmud’s more noteworthy predators: several sources intimate that he essentially sexually molests the Shunammite woman. So his leprosy—though not a direct result of this action—at least keeps him from trying that again]. The reaction to the Amnon incident didn't look like a direct corrective. But it might make sense that it was the impetus.
Finally: everyone needs alone time. It should never be imposed. But even if and when it is—even in a social media age—it’s not always as bad an idea as it looks. It’s been said [I’ve seen it but don’t remember the source] that the only people who actually contracted tzaraas were on a high enough level to actually appreciate a Divine message to decompress. Hopefully we can do that by ourselves, however we do it.
[PS--following that line of thinking, the appreciation of the message to decompress was a more difficult test than that: the correctives took place in public, the metzora being exiled from the camp and in some cases having to call out so as to not contaminate passerby. One only hopes that the more prominent individuals who might be in need of a public correction being able to take one if it comes.]