MSOnline Powershell provides access to a property on MsolUser objects to determine whether O365 thinks the user currently has a mailbox without a license (where one is needed).
Get-MsolUser -UserPrincipalName firstname.lastname@example.org | ConvertTo-Json ... "LicenseReconciliationNeeded": true, ...
A description of this property can be found here: https://docs.microsoft.com/en-us/powershell/module/msonline/get-msoluser?view=azureadps-1.0
MSGraph doesn't appear to provide an equivalent property on the user object.
This property is particularly useful (for me, anyway) where you have shared mailboxes not requiring a license. Sometimes, following migration LicenseReconciliationNeeded is set to $true and we need to assign & then remove a license to clear the flag so that the mailbox isn't removed after 30 days.