The first one moves the pointer out of the map, so that the object it points to is destroyed when the function returns. If the function returns a reference, then that reference will be invalid. It also leaves an empty pointer in the map, which will cause problems later if you try to dereference it - the code assumes the pointers are not empty, and so will have undefined behaviour if they are.
The second leaves the pointer where it is, so the object survives. If the function returns a reference, then that reference is still valid. However, it has undefined bahaviour if the key is not found; it should either check that found != textureMap.end()
, or return *textureMap.at(id)
which will throw if the key isn't found.