Why would they "make" two characters that look (for all intents and purposes) exactly the same?
They didn't look the same, the shapes just happened to converge.「日」depicts the sun:
The horizontal line in the middle (sometimes a dot, sometimes completely absent) was to distinguish「日」from visually similar shapes such as「囗」and「〇」.
「口」(mouth) was originally not confusable with these shapes, being a picture of a mouth with the corners of the mouth obviously drawn:
Unfortunately, the corners of the mouth later disappeared, leaving us with a simple shape commonly confused with「囗」(to surround) and「〇」(a circle) in the modern script.
The character「曰」was created from「口」, being originally a depiction of a mouth with a mark above it representing outwards direction from the mouth, indicating the meaning to speak.
商
甲
前7.17.4
合集8233秦
簡
睡ㆍ法121
現代
楷
標楷體
現代
楷
EPSON正楷
Adding a small mark to represent directionality was part of how the characters「上」and「下」came into being. Both originally used a long horizontal line as a reference, and a smaller mark representing the direction from the reference; the vertical strokes weren't added until later.
The structure of「曰」is very similar to the structure of the synonym「言」.「言」was originally「舌」(tongue) with an additional horizontal mark on top.
For reference,「舌」was originally a picture of a tongue sticking out of a mouth「口」with saliva marks.
There is a further character which has the potential to cause confusion:「甘」(delicious > sweet) was also created from「口」, being originally a depiction of something tasty (represented by a mark) inside of「口」.
商
甲
乙1010
合集21731
篆
說文解字
現代
楷
標楷體
How do you really differentiate them except by context?
Unfortunately, the mark in「曰」sometimes shifted position or was drawn right across the horizontal boundaries of the character. The regular script samples above are from a Taiwanese (標楷體) and Japanese font (EPSON正楷書体), respectively, and in the Taiwanese font the middle horizontal lines span both「曰」and「日」, while in the Japanese font the line does not span either character, making this at best an unreliable way of distinguishing the two.
As individual characters,「曰」and「日」should be distinguished by their width;「曰」is never taller than it is wide, while「日」is always taller than it is wide.
Even this method is unreliable when it comes to component parts of characters, because modern parts of characters obey proportion rules for aesthetic purposes rather than for semantics, and the shape of the component is no longer relevant in this case. This is most obviously demonstrated in the character「晶」, which is really three smaller「日」 stretched to various proportions in different fonts. Fortunately,
As components, we can only distinguish between「曰」and「日」based on the entire character, and not the shape of the component.
References: