I found the fix for this issue (atleast fixed it for my pixel 2 xl)
Goto Settings -> developer options -> Disable automatic routing to USB audio peripherals , and disable this option if it's enabled.
Try it out and let me know how it goes 😊.
Bluetooth has many profiles, ie. modes that have different capabilities. When you're just playing music, the phone is using A2DP profile which is optimized for unidirectional high-quality sound. When you're calling someone, the phone switches to HSP profile, which offers bidirectional sound - but allocating some of the bandwidth for microphone ...