Basically you are taking a subset of encryption using only substitution and calling that a code.
Cipher: exchanging letters to hide a message.
Code: exchanging words/phrases to hide a message.
Encryption: combining math + ciphers (sometimes code too!) to hide a message.
Codes are great for real people having fluent conversations, not so great for computers. We actually use "codes" all the time, but when they're used in large groups (and not a 'secret'), we call it "jargon."
"Push it to main, and I'll pull it in to my buggy branch to see if that works" will make almost no sense to anyone but a programmer who works with git and even then, only someone who's used git since everyone renamed the 'master' branch to 'main.'
So they developed a vocabulary of 411 Navajo words to stand for common military terms. E.g., BESH-LO, which is Navajo for "iron fish", meant "submarine".
The vocabulary included a phonetic alphabet to represent the 26 English letters. E.g., the three Navajo words MOASI, TLA-GIN, and BA-GOSHI all represent English words beginning with C (cat, coal, cow). So, they could spell out arbitrary English words not in their vocabulary.
It was secure against an enemy that lacked Navajos and probably didn't even know what language was being spoken or if they were intercepting some weird form of audio scrambling. But, if the Japanese had been able to translate the messages to English, the code would probably not have survived cryptanalysis for long.
https://www.cia.gov/stories/story/navajo-code-talkers-and-th...
However it sounds like they were mainly used in heavy combat conditions where the enemy didn't have recording equipment for later analysis. So in that scenario specifically (but in that alone) it was pretty secure.
If you've ever gone to a foreign country, you know you will have zero idea what anyone is saying for quite a long time. They knew as long as they kept the messages short enough, nobody was going to learn it from immersion.
There are still ancient languages that nobody have deciphered, despite having copious samples to choose from. I don't think it's as simple as you're making it out to be.