And, to expound and clarify, had the loose ball (loose from the original legal scrimmage kick - that status never changed after the ball was punted) NEVER crossed the neutral zone, there would have been no option to penalize at the spot where the dead-ball belongs to B. That only applies to legal scrimmage kicks that cross the NZ (and free kick plays, too, but we're talkin' scrimmage kicks, here).
On the subject of the ball failing to cross the NZ, let's say the ball went OB at the A-2 (having never crossed the NZ). Some may say, "Well, it was only 3rd down. If Team B were to decline the penalty (for a safety), since the ball didn't cross the neutral, shouldn't it be A's ball, 4th down, where it went OB? No. The down number doesn't matter. By rule, any time a legal scrimmage kick goes OB, the ball is dead where it crosses the sideline and belongs to Team B at that spot - regardless of what down it had been at the snap. Team B may well want to refuse the safety by declining the penalty, and take the ball at the A-2, in hopes of scoring a TD, with, perhaps, a 2-point TD on the Try, to win the game.