Based on your description, this phenomenon may be related to the Network in your company:
When from external of your organization or using mobile data, they mobile device will use the public DNS record to find your Exchange server, so they could to Exchange online.
When connect to the local LAN, the mobile device cannot find a DNS record which points to your Exchange server.
So, confirm with your Network team, make sure all DNS records (Such as autodiscover.domain.com, mail.domain.com. You can refer to the DNS records which are configured on public DNS provider) exist for internal devices which connect to the local LAN.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.