Any time we are dealing with the endzone and momentum and all that stuff, we are going to struggle, so take comfort in the fact that you are not alone. As far as the enforcement goes, 10-3-3c clears it up for you: "'the end of the run is the spot of the catch or recovery when the momentum rule is in effect." So, if you rule B's momentum took him and the ball into the end zone, then no matter what happens in there, a foul by the other team will be enforced at the basic spot, which is end of the run. As noted, the end of the run is the spot of the catch or recovery, in this case the 4. So, we mark the penalty off from the 4.
If, on the other hand, you rule that momentum was not a factor, then that's a different deal altogether. In that case, the basic spot is going to be the end of the RELATED run, which is in the endzone. For fouls in the endzone by the opponent that would naturally be a safety, the spot of enforcement is the goal line. so we enforce that penalty from the goal line.