Kanji were borrowed into Japanese from China more than a thousand years ago. They also borrowed the pronunciations.
But if you’ve ever heard Japanese people try to pronounce English words, you might be able to guess that they didn’t quite get all those Chinese sounds to fit into their existing pronunciation scheme.
But they didn’t let that stop them.
The biggest thing with Chinese was that it had (and still has) tones, whereby identical sounds can be differentiated by changing the pitch of the sound. So you could have two characters make the same sound and yet still be differentiated.
Japanese just abandoned all that when they imported the characters and sounds.
On top of that, sometimes things just sounded identical in Chinese by historical fluke or etymology.
But that’s the treetops reason.
In this case, they aren’t often used as standalone words like that as ゆう. There are dozens of kanji read as こう or しょう, but they usually appear in compounds with other kanji, not just alone like that. Coincidentally, ゆう is actually the native Japanese reading for 夕, not the one borrowed from Chinese, which is せき. But anyway.
夕 appears as ゆう in 夕食 (ゆうしょく) dinner, for instance
右 appears as ゆう in 左右 (さゆう) left and right
For genuine homophones, yes, as you anticipated, context solves it, just like it does for you in English.