In this situation, since A12 fumbled the ball *during or after the foul*, B did not foul during a running play but rather a loose ball play. The fumble behind the LOS converts all previous action into a loose ball play, and the basic spot for a loose ball play is the previous spot.
If A12 fumbled the ball at the A5, recovered it in the end zone, and then was tackled by the facemask (without a second fumble), then the foul by B would be during a running play with the basic spot where A12 was tackled (in the end zone, resulting in a safety). Then 10-5-2 would kick in and the foul would be enforced from the goal line.
See Case Plays 10.5.4.A (Loose ball play ends in A's EZ, previous spot enforcement) and 10.5.2 (Loose ball play followed by running play, enforcement at goal line)