The words gaol, jail sound the same but have different meanings and spellings. Why do gaol, jail sound the same even though they are completely different words?
The answer is simple: gaol, jail are homophones of the English language.
Chiefly British Variant of jail.
A place for the confinement of persons in lawful detention, especially persons awaiting trial under local jurisdiction.
Detention in a jail.
To detain in or as if in a jail.
Definitions from The American Heritage® Dictionary of the English Language, 4th Edition and Wordnik.
Homophones (literally "same sound") are usually defined as words that share the same pronunciation, regardless of how they are spelled.
If they are spelled the same then they are also homographs (and homonyms); if they are spelled differently then they are also heterographs (literally "different writing").