Every Android phone I've had does this. It's also true with bluetooth headpnones.
This is the very feature that took me away from the iPhone. I always have (bluetooth) earbuds connected. If the buds are not in my ear at the time a notifications arrives, I won't hear it. Frankly, if iPhone had this feature, I'd probably go back. OK, not sure but maybe...
You could probably fix it by using Tasker. I would think you could easily build a profile if headphones connected, notification volume = 0. But then you wouldn't hear it in your headphones either.