That will mimic what Teams is doing to retrieve the user photo
Photo will display in this sample response:
Below sample response is due to the mailbox that is not provisioned or not seen by Microsoft 365:
Regardless where the mailbox resides (on-premise or cloud), user profile photo will be repress from the user mailbox. So make sure that mailbox is provisioned and accessible.
For DirSynced organization, local AD must be synced properly with Azure AD. If it is failing to sync the properties that is needed (specifically “thumbnailPhoto” attributes which is mapped to /photo/$value) you must fix any AD Connect sync problems and make sure both objects are matched properly.
For pure cloud mailbox, allow 24-48 hours for global replication to occur and fix itself. Otherwise you can try to re-provision the mailbox.