The intent of the rule is to encourage Team B to stay in the end zone and take the touchback if there is any doubt about whether he can get 25 yards -- thus decreasing returns and ideally injuries. Once he brings it out and fumbles, all that goes away.
A better scenario here, in my view, might be something along the lines of the Team B player, in the end zone, muffs the kick, which comes out to the field of play where a Team A player tries to possess it but also muffs it, and it goes back into the end zone and OOB. You have a touchback because its still a kick and the impetus hasn't changed, but is it a touchback envisioned by this rule??