My understanding is that unsportsmanlike conduct conducted by a player while the ball is live is a spot foul (much like a personal foul committed by another player well behind the ball carrier). Penalty is enforced from the spot.
It is not accurate to simply say that UNS penalties are enforced from the spot of the foul; it may not be. Unsportsmanlike conduct penalties follow Basic Spot enforcement rules, so the actual enforcement spot varies according to the type of play, and the locational relationship of the spot of the foul to the Basic Spot. Yes, when such a live-ball foul occurs during a TD run, the Basic Spot is the end of the run, which is the opponent's goal line. The 3-and-1 principal is then applied at the Basic Spot. If the spot of the foul is behind the Basic Spot, then the penalty is enforced at the spot of the foul. On a TD run, that will probably be 99.9999% of the time. But, a live-ball UNS foul by the scoring team in the opponent's end zone would be enforced at the goal line, and there are other possible situations in which the penalty might, likewise, be enforced at the end of the related run.