You can remember the meaning of 合法 with this easy mnemonic:
It is unlawful not to close (合) one's mouth when eating. It should be against the law (法)!
Using mnemonics to remember the meaning of Chinese characters like can have an enormous impact on how long to learn Mandarin it takes.