Can someone explain how to fix this visibility issue
It sounds like you have switched on 'In Front' for the blue object. 

That's located on the right column (Properties Editor), on the Object Context tab (orange square icon) in the 'Viewport Display' category. There is a checkbox option for 'In Front'.