Because p1.hashCode() changes when you modify p1, so it can't be found at its original index in the hash table anymore. Never let a hash value depend on a mutable field.
(You're quite lucky that it fails during testing; it might just as well have succeeded, only to fail in production.)