Both of these words are translated as "sea." What's the semantic difference between them?
The usual Arabic word for “sea” is baḥrun, baḥrin, baḥran, al-baḥru etc. These are different inflections of the same word. The other word is yammun, yammin, yamman, al-yammu etc. (all with double mm). This word is quite rare. In the Qur’an it occurs only in the story of Moses and means both “sea” and “river” (specifically the Nile).
In the commentary of A-Safi (1) and the book Lisan Al-Arab (2) the word "الیمّ" is defined as “a very deep sea". Therefore, using this word when narrating the miracle of drowning Pharaoh's clan in a deep sea by the power of Al-Mighty Allah, is more eloquent.
The same word has been used in the story of Moses when he was born:
أَنِ اقْذِفيهِ فِي التَّابُوتِ فَاقْذِفيهِ فِي الْيَمِّ فَلْيُلْقِهِ الْيَمُّ بِالسَّاحِلِ يَأْخُذْهُ عَدُوٌّ لي وَ عَدُوٌّ لَهُ وَ أَلْقَيْتُ عَلَيْكَ مَحَبَّةً مِنِّي وَ لِتُصْنَعَ عَلى عَيْني
put him in the casket, and cast it into the river. Then the river will cast it on the bank, and he shall be picked up by an enemy of Mine and an enemy of his. I And I cast upon you a love from Me, and that you might be reared under My eyes.(20:39)
The word "الیمّ" put eloquently more stress on the great miracle of surviving a newly born baby from such a deep sea.
It is amazing that the word "الیمّ" has always been used in verses which narrate a miracle of Al-Mighty Allah except for one verse where Allah says:
قالَ فَاذْهَبْ فَإِنَّ لَكَ فِي الْحَياةِ أَنْ تَقُولَ لا مِساسَ وَ إِنَّ لَكَ مَوْعِداً لَنْ تُخْلَفَهُ وَ انْظُرْ إِلى إِلهِكَ الَّذي ظَلْتَ عَلَيْهِ عاكِفاً لَنُحَرِّقَنَّهُ ثُمَّ لَنَنْسِفَنَّهُ فِي الْيَمِّ نَسْفاً
He said," Begone! It shall be your [lot] throughout life to say," Do not touch me!" Indeed there is a tryst for you which you will not fail to keep! Now look at your god to whom you went on clinging. We will burn it down and then scatter it [s ashes] into the sea. (20:97)
This verse is about the story of Samiri when he produced for Bani Israel a calf [a lifeless] body and then they took it for God! The word "الیمّ" put an emphasis on humiliating their handmade God by burning it down, scattering its smashes into a deep see and annihilating it forever.
(1) Commentary of A-Safi Volume 2. Page 230
(2) Lisan Al-Arab Volume 12. Page 647