Perhaps try to add some "restriction" MUGEN Trigger?
Something like this:
[State -1, AI Jump]
type = ChangeState
value = 40
triggerall = var(59) = 1
triggerall = StateNo != 40 ;;; some restriction
triggerall = PrevStateNo != 40 ;;; optional
trigger1 = statetype = S
trigger1= ctrl
trigger1 = P2BodyDist X <= 40
trigger1 = P2stateno = 5061
trigger2 = enemynear, numproj = 1 || enemynear,numhelper = 1
If still not working you might need to try to make MUGEN code to count the number of times your MUGEN A.I. jumps then use that count number to make more "restriction" MUGEN Trigger...
But,...........I think the "in the air and never come back down" MUGEN issue might have something to do with your aerial move(s) other than your jump start state #40..........you might want to check your aerial move(s) states too......