The first thing to ask yourself on these plays is “What is the natural result of the play?” Then determine the basic spot, then the enforcement.
In scenario one, the ball is dead and A is in legal possession of the ball when they recover it. Because batting is a 3-and-1 foul, we need 3 things: When did the foul occur (what type of play), who committed the foul, and where the foul was committed. This foul occurs during a scrimmage kick play. So now we have to determine if it meets the requirements for post scrimmage kick enforcement. Because Team B will not put the ball in play next, PSK does not apply. So now we apply the 3-and-1 principle. The basic spot for a scrimmage kick play is the previous spot. The foul was committed by the team not in possession, so the foul will be enforced from the previous spot. However, Team A is in legal possession, so they would just decline the penalty and have the ball 1st and goal at the B-5.
In the second scenario, Team B is in legal possession at the end of the down. The foul still occurs during a scrimmage kick play, but this time all PSK criteria are met. So the basic spot is the PSK spot. The kick ends in the field of play when it is possessed by Team B and none of the special cases in 2-25-11 apply, so the PSK is the end of the kick. The foul is committed by the team taken to be in possession and the foul is behind the basic spot, so it is enforced from the spot of the foul. Since this foul is in the end zone, the penalty is a safety.
One other note, PSK does not apply in extra periods. So if scenario 2 were to happen in OT, the penalty would be from the previous spot just like scenario 1.
Also, this is NOT an unfair act. The NFL counts the field goal in this scenario, NCAA does not. It is simply a foul for batting and you enforce as above.