The code changes the index buffer format on built-in resources. As described in documentation this clears the index buffer and resets submesh count to 1. This persists even outside of playmode because the GPU data was cleared. Between entering and exiting playmode the GPU data is not re-uploaded. This would put a big burden on entering playmode. Restarting the editor fixes the problem as the meshes are loaded from disk again and the buffers are uploaded to GPU.
In this case I'd advice creating a copy of the original and modify that as desired. Or you need to restore the things that are cleared by changing the index format (set the submeshes up again and fill the index buffer). Note that also in a similar way you could change the vertex positions inside the buffer on the GPU. Those changes will persist across playmode too.
related documentation:
https://docs.unity3d.com/ScriptReference/Rendering.IndexFormat.html
https://docs.unity3d.com/ScriptReference/MeshFilter-sharedMesh.html
https://docs.unity3d.com/ScriptReference/MeshFilter-mesh.html