こんにちは (Konnichiwa) AydenY,
Good question! These two なん (nan) are actually different things. The first 何 (nan) is the question word “what,” whereas the second なん (nan) is the explanatory なん (nan). You can read all about it in this lesson:
https://app.rocketlanguages.com/members/products/5/lesson/5182
Essentially, you can add なん (nan) after な (na) adjectives or nouns to provide an explanation on something or ask for more information about something. So 好きなんですか? (Suki nan desu ka?) is actually asking the listener for more information about whether or not they like something (i.e. why or why not they like it).
In contexts where なん (nan) means “what,” you will nearly always see it written in kanji: 何.
Just like you said, some words are typically written in kanji, while others are typically written in kana, despite the fact that they have kanji. Whether or not the kanji is used usually depends on how the word is being used in the sentence.
For example, 来る (kuru) “to come” is used with kanji when it means “come"; however, when is used as part of a grammatical structure like 〜てくる (~te kuru) (e.g. 行ってきます (itte kimasu) “I'm off”), it usually uses kana, since it doesn't really keep it's original meaning here.
This can be a little confusing to get your head around, so we've provided explanations throughout the course on when certain kanji should or should not be used. As you practice more and more sentences, you'll pick it up soon enough!
I hope this helped. Please let me know if you have any other questions.
勉強を頑張ってください! (Benkyō o ganbatte kudasai!)