"Which planet is nearest Earth?" vs "Which planet is the nearest to Earth?"
Both sentences are correct. They express different ideas. The sentences revolve around the use of the word "nearest." In the first sentence, "nearest" is functioning as a predicate adjective. In the second sentence "nearest" is functioning as a noun which is being modified by the article "the."
It is possible to omit "to" and still have a grammatical sentence: "Which planet is the nearest earth." It sounds strange but if we substitute "one" for "earth," it forms a sentence which doesn't sound strange; "Which planet is the nearest one?" In this sentence, "one" is an adjunct.
Something being grammatical and making sense are frequently two different things.
Also, note that "earth" can either have "the" as an article, which designates it as a planet, or not, which is giving it a name, Earth. For example, "Which woman is nearest Michael?" (some speakers will say "Which woman is closest to Michael.") "Michael" is a proper noun and doesn't need "the." Grammatically-speaking it is not incorrect to say "Which woman is closest to the Michael," but it is not something English speakers say because the usage is not recognized as making sense and isn't supported by the corpus. Earth is a proper noun that can use "the."