Play ended with a loose ball behind the line of scrimmage, making everything that happened before it including the foul, part of the loose ball play. Enforce from previous spot. The fact that the ball had at some point been beyond the NZ is insignificant.
I agree, now examining the Rule Book.
Normally, this would be enforced at the 38 if the line of scrimmage was before the 38. But since the line of scrimmage is the 40, we treat this as a loose ball play, and enforce at the 40.
10-6: Enforcement Spots, All-but-one-principle
A loose ball play is action during:
3. A backward pass (including the snap), illegal kick or fumble made by A from in or behind the neutral zone prior to a change of team possession.
So, this fumble was behind the line of scrimmage, so it's a loose ball play.