The etymology of “legitimate” and “legal” are shared but they have very different meanings. If you are not a native speaker of English then these connotations can be hard to discern since word meanings are fluid and regional, but at least in the US the meanings are quite different.