The iterator doesn't copy the list of keys so when you change the underlying data you are making it invalid.
You need to make a copy yourself:
B4X:
Dim KeysToRemove As List
KeysToRemove.Initialize
For Each Index As Int In mapX.Keys
KeysToRemove.Add(Index)
Next
For Each k As Int In KeysToRemove
mapX.Remove(k)
Next