Not sure I completely agree Legacy Zebra. This play is a scrimmage kick play per Rule 2-17-6; the kick occurred before a change of possession, and there is nothing in Rule 2-17-6 or 10-2-4 that states the kick itself must be legal. Therefore, in addition to the option of safety if penalty accepted, Team B could have added penalty yardage (10 yards or 1/2 distance to goal line) if the Team B runner was tackled short of goal line.
No clue whose rules you are referencing, but it ain't NCAA, which, with UIL exceptions, is what is used here in Texas. 2-16-1 addresses what constitutes a legal kick, and, to be legal, the kick must be made according to the requirements for any of the three legal types of kicks (punt, drop kick, or place kick). No other type of kick is legal. The kick in question was none of those legal types of kicks.
Per 2-16-7, a scrimmage kick
play requires the kick to be one of the three legal kicks described in 2-16-1. Since it was not a legal kick, this was not a scrimmage kick play.
There is a difference between an "illegal kick" and "illegally kicking the ball". An illegal kick is a kick made in accordance with the requirements of one of the three types of legal kicks, but at a
time when such a kick is not permitted. When an "illegal kick" is made, the ball is dead. The penalty is 5 yards (enforcement spots vary, by rules).
By 6-3-10, "Illegally kicking the ball" is kicking the ball not in accordance with the requirements of one of the three types of legal kicks (regardless of when or made or any other circumstance). By 9-4-4, kicking a loose ball or ball held by an opponent is illegally kicking the ball, and the penalty is 10 yards, with Basic Spot enforcement, and loss of down, if by Team A before a change of team possession.
So, in the down in question, the ball was loose from the snap, which is a backward pass, when it was kicked by the Team A player. That's a foul for illegally kicking the ball. The ball, and, thus, the foul, was in A's end zone. Per Basic Spot enforcement, the Basic Spot for this foul is the Previous Spot. Per the 3 & 1 principal, the spot of the foul is behind the Basic Spot, so the enforcement spot is the spot of the foul. Since the spot of the foul is in their own end zone, the penalty results in a safety, 2 points for B, if elected. On this down in question, the live ball was legally recovered by B and advanced across A's goal line for an apparent TD. Team B has the option to decline the penalty for Illegally Kicking the ball, and take the result of the play, i.e., Touchdown, which they did.
The crew handled it properly, although it took the R quite some time to process what happened and drop his flag in the end zone. But he did, and they completed the penalty properly.